Implemented BFS and changed a few other functions