Implemented exception handling