refactored exit gate operation.