Fixing imports and resource leaks