refactor api client

Still need more tests