exit() refactoring