Added variable initialisation for lastX and lastY