General code cleanup: fix imports, spacing, exceptions, and use of final