off by 1 index error in alg1