Changed the way the counts by types are handled.

Numerical type indices and lists are now used instead of a dictionary, to speed things up.