rebase patch to trunk and fix for TEZ-1041