Major refactoring to make factory interfaces more consistent and generic.