Fix event x and y bug introduced in cleanup and also fix npe when there isn't an image yet.