Fixed a bug when a list of classes was empty.

In certain scenarios an empty list of classes could be checked, which would cause an error. This has been fixed.

References #505