Esc key exit modified to avoid crashes.