Factor out some utility functions.