fixed error handling.