We should rebase this patch on top of master in light of #595