Corrected memory allocation/deallocation errors in the output