Fixed bug causing wrong counting