modify the main.cpp, add the control logic