simplified away the inner loop in the r script, added bench mark