huge refactoring of pathfinding