Minor refactoring to expose some useful functions.