Fix for issue #1026. Related to #978 and #1016.