Move code out of main into client, especially code for command-line processing, since we need to access command-line processing from regression test code. Also added beginning of regression test code.
a few fixes related to last merge (also lost some code, so commented out the beginnings of getting it back).