Refactor common code to a separate file.