issue #663 fixed (ported from master)