rewritten to make use of official client api.