Fix ancestors list, refactor inheritance and polymorphic code.