Merge "Tidy-ups and refactoring"