Bug fix to ensure routing through friends, no longer causes exception
Use argparse; add option to specify JSON config file

There is a global dictionary named CONFIG. Initially it contains default
values, but a JSON configuration file can be provided using the
`--config` flag. The values set in the configuration file will overwrite
the default settings in the CONFIG dict.

Several function argument defaults changed to None (with a conditional
inside to use the default value from CONFIG) because the configuration
file is not read until *after* the function definitions are executed.