diff --git a/include/polly/Support/GICHelper.h b/include/polly/Support/GICHelper.h
index 2b3bb31..0266ef3 100644
--- a/include/polly/Support/GICHelper.h
+++ b/include/polly/Support/GICHelper.h
@@ -188,6 +188,7 @@ template <typename T> class IslObjTraits;
   template <> class IslObjTraits<isl_##TYPE> {                                 \
   public:                                                                      \
     static __isl_give isl_##TYPE *copy(__isl_keep isl_##TYPE *Obj) {           \
+      llvm::errs() << "copy" << "\n"; \
       return isl_##TYPE##_copy(Obj);                                           \
     }                                                                          \
     static void free(__isl_take isl_##TYPE *Obj) { \
@@ -251,25 +252,36 @@ private:
   T *Obj;
 
   explicit IslPtr(__isl_take T *Obj, bool TakeOwnership)
-      : Obj(TakeOwnership ? Obj : Traits::copy(Obj)) {}
+      : Obj(TakeOwnership ? Obj : Traits::copy(Obj)) {
+    llvm::errs() << "Take ownership: " << TakeOwnership << "\n";
+      
+      }
 
 public:
   IslPtr() : Obj(nullptr) {}
-  /* implicit */ IslPtr(std::nullptr_t That) : IslPtr() {}
+  /* implicit */ IslPtr(std::nullptr_t That) : IslPtr() {
+    llvm::errs() << "Move That3\n";
+  }
 
-  /* implicit */ IslPtr(const ThisTy &That) : IslPtr(That.Obj, false) {}
+  /* implicit */ IslPtr(const ThisTy &That) : IslPtr(That.Obj, false) {
+  
+    llvm::errs() << "Move That2\n";
+  }
   /* implicit */ IslPtr(ThisTy &&That) : IslPtr(That.Obj, true) {
+    llvm::errs() << "Move That\n";
     That.Obj = nullptr;
   }
   /* implicit */ IslPtr(NonowningIslPtr<T> That) : IslPtr(That.copy(), true) {}
   ~IslPtr() { Traits::free(Obj); }
 
   ThisTy &operator=(const ThisTy &That) {
+    llvm::errs() << "Const copy\n";
     Traits::free(this->Obj);
     this->Obj = Traits::copy(That.Obj);
     return *this;
   }
   ThisTy &operator=(ThisTy &&That) {
+    llvm::errs() << "Copy &&\n";
     swap(*this, That);
     return *this;
   }
diff --git a/lib/External/isl/isl_space.c b/lib/External/isl/isl_space.c
index b4b88b7..7f81a99 100644
--- a/lib/External/isl/isl_space.c
+++ b/lib/External/isl/isl_space.c
@@ -111,15 +111,24 @@ static __isl_give isl_space *mark_as_params(isl_space *space)
  */
 isl_bool isl_space_is_params(__isl_keep isl_space *space)
 {
+        printf(" is_params: space %ld\n", space);
 	if (!space)
 		return isl_bool_error;
+        printf(" a\n");
 	if (space->n_in != 0 || space->nested[0] ||
 	    space->n_out != 0 || space->nested[1])
 		return isl_bool_false;
-	if (space->tuple_id[0] != &isl_id_none)
+        printf(" b\n");
+        printf("space->tuple_id[0] %ld\n", space->tuple_id[0]);
+        printf("isl_id_none %ld\n", &isl_id_none);
+	if (space->tuple_id[0] != &isl_id_none) {
+                printf("return false\n");
 		return isl_bool_false;
+        }
+        printf(" c\n");
 	if (space->tuple_id[1] != &isl_id_none)
 		return isl_bool_false;
+        printf(" d\n");
 	return isl_bool_true;
 }
 
@@ -1768,6 +1777,7 @@ __isl_give isl_space *isl_space_params(__isl_take isl_space *space)
 
 __isl_give isl_space *isl_space_set_from_params(__isl_take isl_space *space)
 {
+        printf("isl_id_none  aaa %ld\n", &isl_id_none);
 	if (!space)
 		return NULL;
 	if (!isl_space_is_params(space))
diff --git a/lib/Transform/FlattenAlgo.cpp b/lib/Transform/FlattenAlgo.cpp
index bd1ce4d..acd7220 100644
--- a/lib/Transform/FlattenAlgo.cpp
+++ b/lib/Transform/FlattenAlgo.cpp
@@ -379,6 +379,13 @@ IslPtr<isl_union_map> tryFlattenLoop(IslPtr<isl_union_map> Schedule) {
 } // anonymous namespace
 
 IslPtr<isl_union_map> polly::flattenSchedule(IslPtr<isl_union_map> Schedule) {
+  isl_union_map *SPtr = Schedule.copy();
+
+  errs() << "flattenSchedule - SchedulePtr: " << (long)SPtr <<"\n";
+  auto SSpace = isl_union_map_get_space(SPtr);
+  errs() << "flattenSchedule - isParams: " << isl_space_is_params(SSpace) << "\n";
+  isl_space_free(SSpace);
+  isl_union_map_free(SPtr);
   auto Dims = scheduleScatterDims(Schedule);
   DEBUG(dbgs() << "Recursive schedule to process:\n  " << Schedule << "\n");
 
@@ -395,7 +402,9 @@ IslPtr<isl_union_map> polly::flattenSchedule(IslPtr<isl_union_map> Schedule) {
   // Fixed dimension; no need to preserve variabledness.
   if (!isVariableDim(Schedule)) {
     DEBUG(dbgs() << "Fixed dimension; try sequence flattening\n");
+    auto SS = Schedule.copy();
     auto NewScheduleSequence = tryFlattenSequence(Schedule);
+    isl_union_map_free(SS);
     if (NewScheduleSequence)
       return NewScheduleSequence;
   }
diff --git a/unittests/Flatten/FlattenTest.cpp b/unittests/Flatten/FlattenTest.cpp
index 0880629..21c0831 100644
--- a/unittests/Flatten/FlattenTest.cpp
+++ b/unittests/Flatten/FlattenTest.cpp
@@ -10,6 +10,7 @@
 #include "polly/FlattenAlgo.h"
 #include "polly/Support/GICHelper.h"
 #include "gtest/gtest.h"
+#include "isl/options.h"
 #include "isl/union_map.h"
 
 using namespace llvm;
@@ -25,13 +26,22 @@ namespace {
 /// @result Whether the flattened schedule is the same as the expected schedule.
 bool checkFlatten(const char *ScheduleStr, const char *ExpectedStr) {
   auto *Ctx = isl_ctx_alloc();
+  isl_options_set_on_error(Ctx, ISL_ON_ERROR_ABORT);
   isl_bool Success;
 
   {
+
+    errs() << "----------------- Next test\n";
     auto Schedule = give(isl_union_map_read_from_str(Ctx, ScheduleStr));
     auto Expected = give(isl_union_map_read_from_str(Ctx, ExpectedStr));
-
-    auto Result = flattenSchedule(std::move(Schedule));
+  
+    isl_union_map *SPtr = Schedule.copy();
+    errs() << "checkFlatten - SPtr: " << (long)SPtr <<"\n";
+    auto SSpace = isl_union_map_get_space(SPtr);
+    errs() << "checkFlatten - isParams : " << isl_space_is_params(SSpace) << "\n";
+    isl_space_free(SSpace);
+    auto Result = flattenSchedule(Schedule);
+    isl_union_map_free(SPtr);
     Success = isl_union_map_is_equal(Result.keep(), Expected.keep());
   }
 
