That is absolutely positively not how you create an EPUB.
You are doing a tremendous amount of work, to get broken output, when very easy options are available that already work perfectly.
You create an EPUB by converting the document itself from .docx to EPUB. Either with
calibre, or with Toxaris'
Word Addon.