Assorted code cleanup (tightening scope/accessibility, adding "final" liberally, refactoring)