Duplicated code refactoring