Changed the class discovery formula to be more foolproof.