Refactor the whole API