adding error message if malloc fails