Merged upstream with stashed changes. Minor API changes.