Backport changes in moses.