Refactor MPI pollAndProcess function