full functioning cpp file

should be mostly fine except for maybe some cleaning up here and there