Fixed synchronized block issue for multithreading