refactor to use nx graphs to store paths