Added -n parameter to control number of threads.