Restructured the client code