Locking and performance improvements