added key-indexed counting