More work on the 404s

I think this now works pretty much as expected. This adds in our 404 pages where appropriate. 

It's a bit clunky and I would appreciate a more thorough code review.