Fix for #959

Please review the changes and let me know if I need to make changes to it.