Hmmm! sounds a bit complicate.
Simple is best when you plan to convert an epub to mobi.
You only really need <div>
to open and close each xhtml file if it's basic fiction prose. i.e. one before the first <p> section, and one after the last. Note: not the cover page .htm, that's a bit different.
Actual paragraphs only need...<p class=MsoNormal> text in here </p>
for a paragraph break, i.e. blank line.
Simple coding yeilds better results for mobi conversion.
the little brush button (Tidy) will more often than not add superfluous tags and other bits and peices. Working with it off, if your making a file to convert, is advised. If you make a boo-boo you will get a "not well formed" error which will highlight the problem. You can then fix it manually, or automatic and clean up as required.