More refactoring and removing duplication