changed the loop for waiting for the esc key to be pressed to a do/while loop