refactor common code