Fixed edit function with sorted list.