refactoring code to add digraph