Fix exception handling.
(don't try to roll back if app wasn't initialized yet)
Add source to end of document.