fixes #1821

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