Code cleanup.
WriteServiceOutputChecked
Polishing the restore.
Shorter code.
New test and some cleanup.