Changed algorithm to allow for models without supertypes