cp.cpp working version