Refactor duplicated form code