Refactoring API and add docs