Fixed indexoutofrange issue