added more validations and handled input errors