Refactor shared code into single method.