Fixed possible multithreading issue.