Fix the iterators
Port more API from upstream
Fix more consts