[fix] parameter names
[fix] it need to be end-1 because it is inc'ed at end of loop