move the freeing of end_list to fix leak