Cleaning up unused imports and possible null dereferences