Corrected memory allocation errors