Some cleanups and small refactorings with the type system.