Fix read out of bounds error