Ported over Jason Zaugg's fix in branch 2.1.x to master.