Refactoring some API functions