Added more validation for invalid input