Refactoring api, this is wip