refactored gatherXY