Updated the code to fix issues with user input