a bit of const correctness and thread swap condition to aid debugging