Fix indexoutofbounds exception