making efforts to rewrite everything in cpp