Fixed the threading problem