Fixed the index out of bound exception.