Refactor form to avoid duplicated code