Might I suggest keeping Calibre out of your process? It gives you all kinds of Calibre classes that are meaningless. It is far better to clean up your stylesheet and giving your classes clear names that indicate the purpose. That makes it much easier to maintain.
Calibre is a nice program, but don't use it for coversions to ePUB if you can avoid it.