Refactor the form functionality to functions.