Pathfinding enhancements and a few more bugfixes for issues found by @afflicto