Partial backport ogf #1137; Fix #1131