refactored BFS code
implemented dijkstra's algorithm