fixes issue #3461

this fix might be quite delicate and needs to be tested further...