refactored mpi.cpp