solved edge case where nthreads < length(x)