Refactoring the form code