started improving terrain flattening code