This mainly rebases against master, and fixes the two minor problems already pointed out. I would like feedback on breaking the API for this.