fixes #1741

Fixed the issue and committed code for review, please check it.