transforming crap code into nice, structured c++