Rebase Nils's patches.

Re