added an onExit method