Doing some work to speed up depthFirst and breadthFirst searches