Fix for issue #1004 and issue #989