Condense program written in C++