Added a command line tool and tests, plus various client fixes.