TypeRep abstraction.

Not the two commits. The second commit are the type errors that were not there before the refactoring.