Code fixup and refactoring.