Porting #859 to master
Merge pull request #863 from jonhyman/feature/port-859

Porting #859 to master