Initial refactoring work