more refactoring of the api client