Optimize imports

Fixes #1133.
Fix this and other formatting errors