diff --git a/src/Search/Search.hs b/src/Search/Search.hs
index e60b044aafe8459ff3cc8fa446be69e2d55aac8b..c21ea71c714028201c30ec294bc84f493ddb6741 100644
--- a/src/Search/Search.hs
+++ b/src/Search/Search.hs
@@ -1,4 +1,5 @@
 {-# LANGUAGE LambdaCase, OverloadedStrings #-}
+{-# LANGUAGE ViewPatterns #-}
 
 module Search.Search (driver) where
 
@@ -160,8 +161,8 @@ graph2Dot is graph =
     nodeStr from tos = mconcat $ map (arrow from) $ S.toList tos
     arrow from to = "  " <> nodeId is from <> " -> "
       <> nodeId is to <> " [label=\"" <> edgeLabel (fst from) <> "\"];\n"
-    edgeLabel txt = T.dropEnd 1 $ T.dropWhileEnd (/='_') $
-      T.drop (T.length "OSEKOS_") txt
+    edgeLabel (T.stripPrefix "OSEKOS_" -> Just txt) = T.dropWhileEnd (=='_') $ T.dropWhileEnd (/='_') txt
+    edgeLabel txt = txt
 
 dotNodes :: Bool -> Graph -> Text
 dotNodes is = foldMap formatNode . allNotes