Moved more html into functions in report_helper.php

The code needs to be extensively restructured and modulating it should help with
memory management.

I also found and fixed a couple "bugs". Some loops were continuing to completion even though there was nothing left for them to do. I inserted break statements to
fix this.