More cleanup of main(), writing option parsing code, adding support for daemonizing