encapsulated whole script and added private methods
added ESC key support and cancel event