Refactor common function.