moved more stuff from index.php to output.php