Code cleanup

Whitespace fixes, unneeded casts removal, import sorting, etc.