Count instances of a class in an array