working fold_op_cmp implementation