Fixed compiler warnings
Handled data race between threads