Fixed thread safety related bug.