Factor out shared functions into separate source files.