following convention of using k as selected iterator variable
minor optimizations to Count