Add form factory, and fix issue #46