Add flags to flags.py.  Implement log_scan API.  Some bug fixes.