That code doesn't work if X==X2. The same with Y and Y2.