Refactor using haigha
Reorganize code
Add a wrapper around management api
Fix tests