I fixed the XML output so that it doesn't try to put the headers there at the start of every month, just the start of the whole document. I also made it so that it will make three tries per month if it gets timeout errors.
Any feedback on this would be appreciated.