Changes to support trio data.
Big merge from upstream.