cleanup and added command line param for thread count