refactoring and tests using Input and Output