Partial upstream merge.

Still need to validate how some changes interact with our own.