added more validation and error messages