improving breadthFirstSearch