API code refactoring