Fix bug that prevented accessing the last element in the list