Number of items per sitemap file

There is a bug if you have more than 50000 items to add. If you test current code with test I provided you will notice that only one sitemap file is created and that it contains 50001 items which is invalid. When I fixed that bug I noticed that second sitemap file is the same as first one. That's because that file should contain only one item and when you create content for that file, by current code, your array is created like this $this->files[$this->totalFiles] = implode("\n", $this->items); and after that you set $this->items = array($item); That means that second file contains same items as first one. If I have more items in second sitemap file everything will be ok but I do not have and that's the reason of that bug. We should first set $this->items = array($item); and after that populate array $this->files[$this->totalFiles] = implode("\n", $this->items); 
It works most time but there is problem if someone has 50001, 100001... items.

I also noticed that class variable $currentFileByteSize is never increased - it always get value of current item.