fix bug: thread lock
optimize: delete test code
add tests