mismatched delete[] and free() errors fixed