Do less unnecessary work!

Also less nesting!

And it only invalidates the DOM once per message now, so less bottlenecky.