Output Rewrite + Other Adjustments

I've completely rewritten output.php and made a few changes to the other files. Everything seems to be functioning normally now.