Fixes stream flush and adds better stream flush logging.