change protocol and fix some bugs