Fix index exception, and fix #2952