Refactoring of the graph algorithms