Some more whitespace cleanups.
Make sure not to override the "referer" if it exists.

refs #219
Move navbar HTML-generating code where it belongs.

This fixes #219 as we don't need to assemble a string anymore that gets later
printed during the HTML assembly but we rather include the relevant parts right
where they are used. commit:0246f17 is necessary to set the referrer
appropriately so the "Back" button returns to the desired (initial) referrer.