Fixed the threading bug finally