Fixed index out of range exception.