fixed #5984 and improved test coverage
3 files changed