serial code
transform to c++