Refactoring to extract shareable code outside