Refactoring extracting common functionality