fixed a bug causing number of items being counted incorrectly