add max threads
add some tests and make getThread return option