fixed part of it, but still broken by trying to write to the same stream multiple times.