Added form validation and error handling