fix the dynamic array, meaning: store the array in the sorted order and cut off the trailing empty entries
fixing the dynamic array