Refactoring api module: move code from util package to api module
Add a few unit tests