refactoring code which makes node in digraph