implementation for reduce-kv