major refactoring the api