Started refactoring using api lib