major refactoring and bugs corrections in the logic of type inference and type reification