Modified maim.cpp