fix first part of bug #677, for second see feature request #688.