It looks like we always use  i-1, so lets rewrite this loops to start at 0.