Fix to thread safety issue