Minor refactoring to eliminate some duplicate code.