added error messages for unsuccessful memory allocation