refactored to accept user input