form validation and clean up