 	}
 	
 	~Vector() {
-		if(! isOriginal_) // cuda-kernel constructs a copy of the object and then call its destructor
+		if(*smart_ptr_counter_ > 1) {// cuda-kernel constructs a copy of the object and then call its destructor
+			(*smart_ptr_counter_) -= 1;
 			return;
+		}
+		
+		delete smart_ptr_counter_;
+		
 		if (isCPU_)
 			delete [] data_;
 		else

private:
	const unsigned int size_;
	const bool isCPU_;
	const bool isOriginal_;
	
	float *data_;

public:
	Vector(const unsigned int &size, const bool &isCPU) : size_(size), isCPU_(isCPU), isOriginal_(true) {
		if (isCPU_)
			data_ = new float[size_];
		else
			cudaMalloc(&data_, size_ * sizeof(float));
	}
	
	Vector(const Vector &v) : size_(v.size_), data_(v.data_), isCPU_(v.isCPU_), isOriginal_(false) {}
	
	Vector(const Vector &v, const bool &isCPU) : size_(v.size_), isCPU_(isCPU), isOriginal_(true) {
		if (isCPU_) {
			data_ = new float[size_];
			if (v.isCPU_)

	}
	
	~Matrix() {
		if (*smart_ptr_counter_ > 1) {
			(*smart_ptr_counter_) -= 1;
			return;
		}
		
		delete smart_ptr_counter_;
		
		if (isCPU_)
			delete [] data_;
