Made changes to error handling