Close database explicitly
Remove some unused imports and variables