Refactor common code.