Fix length on restore

Also fix up a few tests and add more tests