beforeExit can be used for the validation