Added form validation and improved discard functionality.