Cherry-picked two commits from Pull Request #8:

- ae0d522e1e216b177040546c7c6ba1b120a51877
- 1eed956db3224d3d99a9c0dc8401dd9f2dd2d691