Minor refactorings to make some things cleaner.
More cleanups in code.