added a method to help iterate the graph