Move all of the above into a separate method.