Some cleanups and Cython updates in terrain.py.