long polling, fix some bugs