Fixed another bug with cached imports. Closes #1641