Refactoring some API stuff