add constness in prep for refactoring out a buffer
Revert "add constness in prep for refactoring out a buffer"

This reverts commit 6876c59fc216bccf81a9e42fe2c40b6e06d3bb0c.
get thread ID and prevent undefined behavior, scope iterator to prevent warnings... and possible UB