refactored function API