Code cleanup

Remove unused classes and imports.
Improve type checking.
Add some @SuppressWarnings annotations.