Refactor duplicated code.