some code cleanup, started to add terrain flattening