Proper import cloning with cache. Fixes #1546