get index from HW6 for bug fix