cleaned and added more comments
added exceptionhook to handle unhandled exception gracefully