moved xy_distance to helper file