Cleanup; fix issue with flushing output buffers