More refactoring and reformatting. Some other tweaks.