Change Exception handling and did some formatting