Fix to resolve #946

Please review the fix and let me know if it does good.
indentation is a bit off here