refactor form functionality