Added 'addFinalizer = FALSE' everywhere applicable in order to ensure propper release of the in-memory xml object
Added addFinalizer = FALSE, as well as free(doc) and other houskeeping stuff to close memoryleak