Some refactoring of types to help simplify the interface.