Add critical section to avoid thread safety issue