Move these lines below if (deltaX > 0) {