fixed error handling
cleanup