fix a couple of bugs in calculation in coordinates.