diff --git a/Demo2.cpp b/Demo2.cpp
index ad95e73b70497f495b762c47a89f68e838ed7f31..5e3b6c00db976449bd8187c9a7c64819666d24bd 100644
--- a/Demo2.cpp
+++ b/Demo2.cpp
@@ -41,10 +41,10 @@ int main(int argc, char **argv)
       frame_counter++;
       std::stringstream ss;
       ss << frame_counter;
-      std::string fileName = "dataset/frames/" + ss.str() + ".png";
+      auto fileName = "dataset/frames/" + ss.str() + ".png";
       std::cout << "reading " << fileName << std::endl;
 
-      cv::Mat img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
+      auto img_input = cv::imread(fileName, CV_LOAD_IMAGE_COLOR);
 
       if (img_input.empty())
         break;
diff --git a/Main.cpp b/Main.cpp
index e28eb04c56ee36519979bba71d55e09a56b813a1..94bf8dd2c53c0f013a8487e67575ff6a8d1ccd63 100644
--- a/Main.cpp
+++ b/Main.cpp
@@ -38,11 +38,11 @@ namespace bgslibrary
 
       try
       {
-        int key = KEY_ESC;
+        auto key = KEY_ESC;
 
         do
         {
-          VideoAnalysis* videoAnalysis = new VideoAnalysis;
+          auto videoAnalysis = std::make_unique<VideoAnalysis>();
 
           if (videoAnalysis->setup(argc, argv))
           {
@@ -56,7 +56,6 @@ namespace bgslibrary
           }
 
           cv::destroyAllWindows();
-          delete videoAnalysis;
 
         } while (key == KEY_REPEAT);
       }
diff --git a/VideoAnalysis.cpp b/VideoAnalysis.cpp
index 03e47b3bef3af8f0628d205231ffef1ffd6f8554..9ec0754de53fcf11458ecae26ad7d73d3d323cf4 100644
--- a/VideoAnalysis.cpp
+++ b/VideoAnalysis.cpp
@@ -132,8 +132,8 @@ namespace bgslibrary
 
     do
     {
-      videoCapture = new VideoCapture;
-      frameProcessor = new FrameProcessor;
+      videoCapture = std::make_unique<VideoCapture>();
+      frameProcessor = std::make_shared<FrameProcessor>();
 
       frameProcessor->init();
       frameProcessor->frameToStop = frameToStop;
@@ -154,16 +154,10 @@ namespace bgslibrary
 
       frameProcessor->finish();
 
-      int key = cvWaitKey(500);
+      auto key = cv::waitKey(500);
       if (key == KEY_ESC)
         break;
 
-      delete frameProcessor;
-      delete videoCapture;
-
     } while (1);
-
-    delete frameProcessor;
-    delete videoCapture;
   }
 }
diff --git a/VideoAnalysis.h b/VideoAnalysis.h
index f548a7bfcb50f981780825034dc2a324de077ae2..b41d9ba3f95c02d44c7cf137d70a05be868623a4 100644
--- a/VideoAnalysis.h
+++ b/VideoAnalysis.h
@@ -27,8 +27,8 @@ namespace bgslibrary
   class VideoAnalysis
   {
   private:
-    VideoCapture* videoCapture;
-    FrameProcessor* frameProcessor;
+    std::unique_ptr<VideoCapture> videoCapture;
+    std::shared_ptr<FrameProcessor> frameProcessor;
     bool use_file;
     std::string filename;
     bool use_camera;
diff --git a/VideoCapture.cpp b/VideoCapture.cpp
index ed8964dda284e387ad9d0f590f09370184ec4a41..6c3a8f24061fa427476b9f2928ca79373a7e6eab 100644
--- a/VideoCapture.cpp
+++ b/VideoCapture.cpp
@@ -90,7 +90,7 @@ namespace bgslibrary
     std::cout << "~VideoCapture()" << std::endl;
   }
 
-  void VideoCapture::setFrameProcessor(IFrameProcessor* frameProcessorPtr)
+  void VideoCapture::setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr)
   {
     frameProcessor = frameProcessorPtr;
   }
diff --git a/VideoCapture.h b/VideoCapture.h
index 8b7cd6306dbcd8352dba52861eccb3b1a412fe45..a4872c314de3dd88e3359c503407762f10e49a75 100644
--- a/VideoCapture.h
+++ b/VideoCapture.h
@@ -18,6 +18,7 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 
 #include <iostream>
 #include <fstream>
+#include <memory>
 //#include <chrono>
 //#include <thread>
 #include <opencv2/opencv.hpp>
@@ -32,7 +33,7 @@ namespace bgslibrary
   class VideoCapture
   {
   private:
-    IFrameProcessor* frameProcessor;
+    std::shared_ptr<IFrameProcessor> frameProcessor;
     cv::VideoCapture capture;
     cv::Mat frame;
     int key;
@@ -65,7 +66,7 @@ namespace bgslibrary
     VideoCapture();
     ~VideoCapture();
 
-    void setFrameProcessor(IFrameProcessor* frameProcessorPtr);
+    void setFrameProcessor(std::shared_ptr<IFrameProcessor> frameProcessorPtr);
     void setCamera(int cameraIndex);
     void setVideo(std::string filename);
     void start();
diff --git a/package_bgs/IBGS.h b/package_bgs/IBGS.h
index 67a05684610fb70b130d871593b40a269de3d967..f08e4eea8572533daa4471c0aea951379a9bd8e2 100644
--- a/package_bgs/IBGS.h
+++ b/package_bgs/IBGS.h
@@ -56,8 +56,6 @@ namespace bgslibrary
       }
       virtual void process(const cv::Mat &img_input, cv::Mat &img_foreground, cv::Mat &img_background) = 0;
       virtual ~IBGS() {}
-      //static IBGS* create(const std::string alg_name);
-      //static std::list<std::string> get_algs_name();
     protected:
       bool firstTime = true;
       bool showOutput = true;
diff --git a/package_bgs/bgslibrary.h b/package_bgs/bgslibrary.h
index be452367aaea003902290a321a8db7ce3f1c513c..f97f162621523b65656c802e24b4de84fdde38d3 100644
--- a/package_bgs/bgslibrary.h
+++ b/package_bgs/bgslibrary.h
@@ -22,7 +22,7 @@ along with BGSLibrary.  If not, see <http://www.gnu.org/licenses/>.
 #include "StaticFrameDifference.h"
 #include "WeightedMovingMean.h"
 #include "WeightedMovingVariance.h"
-#include "MixtureOfGaussianV1.h" // Only for OpenCV >= 2
+#include "MixtureOfGaussianV1.h" // Only for OpenCV == 2
 #include "MixtureOfGaussianV2.h"
 #include "AdaptiveBackgroundLearning.h"
 #include "AdaptiveSelectiveBackgroundLearning.h"