Restructured code in preparation for workflow persisting.