put messageHasFrames earlier and use it when you calculate isEmptyMessage