tweak locking and add simple test.