refactored API implementation