Added refactored begin, rescue, retry code