fixed bug with value of index variable