Refactoring and dropping code duplication