trying to fix the thread safety issue