Refactoring to common code