Backport @moxley's fix to v2 branch