Changed locking to allow for concurrent reading and writing.