Implement naive type equality and hashing. Minor refactoring.