Backported fix for #186 into v2.2