new version from recent pull requests from lovely strangers