Added user input validation. Cleaned up code.