fixed error handling