Add locking

Ensure that the values don't get concurrently accessed.
May need to revisit the granularity, but for the time being this should
be sufficient.