Thanks for sharing this @kode54 
just a note if could be useful for someone else, if you are not using the rewrite urls included into elkarte this should be edited from:
                   '/index.php/topic,'.$row['id_topic'].'.0.html';
      } else {
      	$posturl = $boardurl.
                   '/index.php/topic,'.$row['id_topic'].'.'.$lastpage.'.html';
                   '/index.php?topic='.$row['id_topic'].'.0';
      } else {
      	$posturl = $boardurl.
                   '/index.php?topic='.$row['id_topic'].'.'.$lastpage;
I'm not sure about this:
      $lastpage = (intval(($row['num_replies'] + 1) / 25)) * 25;
Should 25 be replaced with the number of posts  displayed per page? I am using 15 posts per page.