Further reducing code duplication with function factory.