Modified to run with 3 threads