Extract method to refactor out some common code.