Initial refactoring to get us closer to a plugin.