refactoring and adding user input