refactored code, added bidirectional functionality to adjacency list