Ronak's C++ version of the MAPA code