Backport fix for 792 from master to 1-x

backported missing checks to fix issue #792