Used std::auto_ptr to lessen the lines of code.