Pull out client code and separate tests