fixes #1996

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