backporting changes from master