Form refactoring and tests