Rebased 21cd3f9003ec85d7b467a9a1633ad9f5a343ca6c into mast/rewrite.