Refactoring. Extracted common functionality