Port fix for #797
Fix for 793