Merge with upstream. Fix some conflicts.
Remove unused code. [ci skip]