Make stuff less global.

Most functions now take a config as their first arg, so that
we can use a per-server config rather than globals.