cleaned up the cpp file a bit