Refactoring to pull some common code together.