Fix bug where id was captured by reference, not value.

I noticed in my logs that some messages had duplicate ids. I forgot to close over the id value instead of the id reference.