(maint) Refactor type_loader, mostly specs

This cleans up the specs for type_loader a lot and slightly refactors a few
methods in type_loader.