incorporate @ZaidM's fix in #1350