fixed lower bound for inner loop causing it to skip the first element.
fixed index problem with do_select