Fix counting bug