Manually merge in relevant parts of github pull request #163.