Optimize imports

Fixes #1133.