More fix for #901, also complete port of #890