Refactoring, added some comments including for the API documentation