Cleaned up code in graph_path function