Crude implementation of built-in reduce functions