Handle non-existent pages
Error handling
Move globals to top of file and add template caching
Add page title validation
Refactor error handling
* Slight deviation: explicitly create a handler function and return it.
  It is more verbose, but a little easier to understand.