My first guess would be unpropperly closed div tags
Nop unfortunately not divs are closed
<div class="tp-s3"> '.dynamic_sidebar( $right);' </div>
I would start with some PHP logging to see what $right contains. If it contains more or less than what you are looking for you might need to tweak your query.