More cleanups and refactoring prompted by Jenkins