Fix issue 3856
Merge pull request #2264 from shikil/3856_logic

Fix issue 3856