refactor to use the client

Thanks @matthewfl