Clean up

I reduced every declaration scope that I could, as suggested in some places.

No functional changes,