Try Calibre instead of Kindlegen, seems to handle conversion a little more smoothly. i.e. it is far more tolerant about what you input.
Kindle uses <img tags instead of <SVG. Another common conversion bug with Kindlegen is that it ignores blank lines tagged <br>, do a search and replace with Sigil, use
Putting it after the closing </p> will give you a standard font size blank line. Putting it inside <p> tags on a line of its own will give you a nice chapter break sized space. ie <p> </P>
I would try running it through Calibre before you start digging into the code. If it is a well formed epub it should convert without much bother.