Error in def toXY function fixed