Refactored client code into pieces