Added behavior tests
Fix tests
Added query locking