fixes #1919

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