Revert "Revert "partial fix #1199""

This reverts commit 7aae5f03e8fb3010ec093a358719f1ad2e61a2de.
fixes #1199