New version with threads

New version with threads