Re-worked the way config variables are handled.

This is an attempt at reducing the pollution of the global config
namespace, and also to more easily facilitate the addition of settings
for new areas of the application.
Updated some comments.