Server-side processing for History table

Here is the server side processing code for the main History page. I still need to add this to the per-user history page but would probably be best to test this first and iron out any bugs.

There is also some additional code there to improve load times on the home page.

I have only tested this on a Linux box.