refactoring for input