better client code and bug fix in server