Fix delete[] and add ref