Backporting changes from mainline codyco repository