ADD: better exception handling and clean up of main method