Fix for flushing issue at exit