fix flushing and code gen issues.  cleanup.