Sorta got it working (at least it outputs the HTML correctly)