Fixed ranges on A* that caused crash when it reached the edge of the map. Also fixed a few errors introduced while merging.