refactor code to get user inputs