Fixed index out of bound exception