Index out of bounds fix