changed the error handling