Fixed value calculation

was missing last index in array. range(a,b) is a to < b.
Created function description comments