refactored form validation