Better locking, caching fix