Backport last code from @work