Improved exception handling and output format