Backporting changes from upstream