Define functions flatten and keyCounterObject