tidy up coordinate writing code