Some refactoring work