Factor out a utility function.