BUG: Calculating next unset position was wrong
In the case when the Reference Item was being expanded and the next unset position was set to -1 (indicating there were no unset values in the item), the logic incorrectly set the next unset value to the original size + 1 -> it should have been set to the original size (since that was the next unset value).