Added exception handling, unhandled exceptions open an error window and write a log