Factor out some functionality to separate file.