Some refactoring/reorganization