apply refactor to API classes too..

also unified the behavour between the UI and API