refactored api and added a little documentation