cleaned up code, fixed num_cpus bug