start tidying up GenerateIntermediate: pull State stuff out into separate file