Merge master into 1.9

This merges master into master-1.9. It includes #238 and #240 merged such that the 1.9 changes are atop the 1.8 changes, so future merges from master to master-1.9 should be without conflicts.