Refactored the pathfinding code to its own class. Added documentation.