Some minor cleanups and refactoring.