refactor api client