added MPI support and replaced .write with a stream