fix issue 1787

fix the bug described in issue #1787