Merge "Assorted cleanup and refactoring"