rebased for #2162, implemented a better logic to distinguish msg_ts