fix locking and references