Major refactoring to allow more flexible custom form building.