I'm replacing a deck that the previous owner installed because it was sagging. When I pulled the old ledger board, I realized it wasn't really anchored well to the rim joist at all. Upon further inspection it seems that the stack up is odd - it seems the rim joist was only covered with 1/2 rigid foam, then T1-11 for sheathing, then the vertical panel siding. Some of the sheathing is a bit rotted and came off with the old ledger.
How should I go about waterproofing this? I got some flat back flashing and some z flashing, but does the back flashing go under the foam? Do I need to repair the sheathing? Should I cut the sheathing and foam and just lag the ledger directly to the rim joist? This is in Midwest USA, so rain and freezing/thawing are issues.