optimize the client exiting logic.