Added test cases, fixed concurrency problems