Fix for #218

This is a clean version of Pull Request (please discard PR #2158 ).