Solved concurrency issues with locks