Incorporated better error handling.