Client refactoring

Hi Garreth

Consider this a work in progress, for your review. Don't merge yet, as I'm far from done.
I'll continue to commit things to this branch so this PR stays up to date.
Hi @gaye 

Ignoring everything else.. please take a look at this function. It largely keeps your API design the same as it was, but the guts have been changed a bit.