updated with onExit method