Improved exception handling and added commandline flags for extra features.