EDIT: Figured out the problem. Also if you found this through google or another search engine here is where I went wrong and how to fix it.
My delet
Figured out your for loop isn't reaching the desired position you wanted. Better use equal to sign for the constraint it will work. e.g.
for (i=1;i<=position-1;i++) { }