Consolidated a lot of coordinate transformation code.