Fix for issue #1004 and issue #989
Possible fix for issue #954