restructuring server/client code