fixes #1751

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