Big refactoring to make the form validation work