Refactoring clean exit