3.6.x cherry-picks

From commits in master branch by @jimis and @kacfengine.