Rebase + squash + fixup of #814.