Fixed some edge-of-map bugs.
Hacking away at bottlenecks.