Minor code cleanup and refactoring.