fixing arrayindexoutofbounds exception