Fixed issues with setting number of threads. Created a new routine.