Refactor common code to methods.