As an example, give yourself 10 scrap metal and force drop it, only 5 will be dropped.
I believe there's a simple fix to it. Do not iterate over the indices in a page front to back as you are removing items from the list and the indexes will change. Instead, iterate over the items in reverse with for (byte index = count - 1; index >= 0 ; index--) instead of the current for (byte index = 0; index < count; index++).