Fixing Counter's inefficient totalCount() implementation