Cleaned up Hooks code, comments, and documentation.

Essentially rewrote Hooks::run() to get rid of the ridiculous
four levels of indentation. Also made some slight adjustments
to fix rare edge cases (for example, moved set_error_handler
after wfProfileIn in case Profiler triggers an error).

Change-Id: Iafdd4ceedac067b49ac597359ac456f4617da9e8