Remove unused imports
Fix layout issues.
Protect against possible NPEs.