Add state machines to wrapper, data classes. Reorganize caching to use 2 directories for current and previous run. Fix issue with underscore document parameters.