used threading to speed up the process: takes about a minute to finish for 1 setting