major refactoring done with the api