Changed xmalloc style calls to proper malloc calls with error returns at