Added locking functionality. Still have issues with deadlock and parallel reads.