bug fix index out of bounds