error when sorting list

error when sorting list

Hi! I am trying to retrieve the last 5 participants, introduce their names and performances in a list and then sort them and show the ranking in an HTML view. My code is the following:

  1. <tr class="zc-row-header">
  2. <td class="zc-viewrowheader">Name</td>
  3. <td class="zc-viewrowheader"> Correct answers</td>
  4. </tr>
  5. <%index_list = {0, 1, 2, 3, 4};%>
  6. <%name_list = {};%>
  7. <%performance_list = {};%>

  8. <%for each index1 in index_list
  9.     {
  10.         row  =  Session_2_Water_and_jar  [ID != 0] sort by  Added_Time desc range from (index1  +  1) to (index1  +  1);
  11.         name_list.add(row.Name);
  12.         performance_list.add(row.Performance);
  13.     }%>

  14. <%for each index2 in index_list
  15.     {%>
  16. <%max1 = 0;%>
  17. <%max_index = 0;%>
  18. <%for each index3 in index_list
  19.         {%>
  20. <%if (max1  <  (performance_list.get(index3)).toLong())
  21.             {%>
  22. <%max1 = (performance_list.get(index3)).toLong();%>
  23. <%max_index = index3;%>
  24.                                                                                                 <%}%>
  25.                                                                 <%}%>
  26. <tr class=zc-viewrow>
  27. <td><%=name_list.get(max_index)%></td>
  28. <td><%=performance_list.get(max_index)%></td>
  29. <%name_list.remove(max_index);%>
  30. <%performance_list.remove(max_index);%>
  31. </tr>

  32.                                 <%}%>

It was working perfectly for the past 2 weeks but this morning I started getting the following error:
Error details:
Error occured while executing the script.
Unable to evaluate if/while Condition
If I delete the last line, the one with <%performance_list.remove(max_index);%> I get the error:
Error details:
Error occured while executing the script.
'get from list' operation failed as the index is greater than the list size
I checked the value of the index and it is definetely not greater than the list size. Could somebody please help me? What am I doing wrong and how come it worked so far?