Refactor for new API
Bugsquashing.