bug fixes

fix the bugs on processing the messages received.