Take loop logic out of the client, add some command line options