fix error messages not being flushed before exit