fixes #1655

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