Validation of user input and error handling added