C++: refactors code.