Refactoring. Extracted duplicated code