added validation and error messages