fixed client side bug and added some UT for server side