fix index out of bounds