added ESC key functionality for closing and cleaning up the application