API refactoring + global functions