Fixed indexOutOfRange error