Adapt and fix the changes from #6833