Cleanup type-env-structs.

Removes all unused functions and cleans up the remaining ones to have
more consistent and simpler APIs.