Refactor out common code for running workflows.