Did some refactoring in the api