Fixed threading and duplicates problem