More refactoring and duplication removal