Support for ImportTerm (non-caching) and minor reshuffling of code.