Got a lot of it working properly-ish. Finished re-organizing the code so that all the guts except the download mechanics are on the index.php