Improved user input validation