refactoring and Quit method with test