fix a bug in dispatchmessage