Backport fix to #140 for 0.5.1 release.