fixes counting bug