Refactor common code