Factor out some functionality.