review

I did some minor refactoring changes, might be interesting.
I suppose :
 aIndex = result(result, a, aIndex, i); 
and 
bIndex = result(result, b, bIndex, i);

might be somehow generalized