Improved coord change function