TASK 4: fixed errors in index calculations