diff --git a/.gitignore b/.gitignore
index 905cdaf1b4a0c2c1bd65608422000aebc189d6fe..3f5e0f7bbb092306784a68a8dd9a3fdf95c25e08 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,6 @@
 etc/
+build_*/
 binaries/
-package_bgs/pt/
 java_gui/dist/
 java_gui/build/
 java_gui/bgslibrary.exe
@@ -9,6 +9,4 @@ qt_gui/
 fet/etc/
 *.exe
 *.pdb
-vs2010mfc/src/bgslibrary_vs2010_mfc.aps
-*.suo
-vs2010mfc/src/bgslibrary_vs2010_mfc.v12.suo
\ No newline at end of file
+*.suo
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 03338e587fccb3726fa4198d820dcb5fd1c0abf7..d8e60dae5f33cad38be88f2d074d9d0ddbdc676c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,20 +1,33 @@
 cmake_minimum_required(VERSION 2.8)
 
-project(bgs)
+project(bgslibrary)
 
 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++0x")
 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99")
 #set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake-modules)
 
+set( bgs_out_dir "." )
+# First for the generic no-config case (e.g. with mingw)
+set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${bgs_out_dir} )
+set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${bgs_out_dir} )
+set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${bgs_out_dir} )
+# Second, for multi-config builds (e.g. msvc)
+foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
+    string( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
+    set( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} )
+    set( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} )
+    set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${bgs_out_dir} )
+endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
+
 IF(UNIX)
-  # add some standard warnings
-  ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas)
-  
-  # -ansi does not compile with sjn module
-  #ADD_DEFINITIONS(-ansi)
-
-  # if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare
-  #ADD_DEFINITIONS(-Wconversion -Wfloat-equal)
+	# add some standard warnings
+	ADD_DEFINITIONS(-Wno-variadic-macros -Wno-long-long -Wall -Wextra -Winit-self -Woverloaded-virtual -Wsign-promo -Wno-unused-parameter -pedantic -Woverloaded-virtual -Wno-unknown-pragmas)
+
+	# -ansi does not compile with sjn module
+	#ADD_DEFINITIONS(-ansi)
+
+	# if you like to have warinings about conversions, e.g. double->int or double->float etc., or float compare
+	#ADD_DEFINITIONS(-Wconversion -Wfloat-equal)
 endif(UNIX)
 
 find_package(OpenCV REQUIRED)
@@ -25,11 +38,11 @@ message(STATUS "    libraries: ${OpenCV_LIBS}")
 message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
 
 if(${OpenCV_VERSION} VERSION_EQUAL 3 OR ${OpenCV_VERSION} VERSION_GREATER 3)
-  message (FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
+	message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
 endif()
 
 if(${OpenCV_VERSION} VERSION_LESS 2.3.1)
-  message (FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
+	message(FATAL_ERROR "OpenCV version is not compatible: ${OpenCV_VERSION}")
 endif()
 
 file(GLOB sources FrameProcessor.cpp PreProcessor.cpp VideoAnalysis.cpp  VideoCapture.cpp)
@@ -37,40 +50,44 @@ file(GLOB main Main.cpp)
 file(GLOB demo Demo.cpp)
 file(GLOB demo2 Demo2.cpp)
 
-list(REMOVE_ITEM sources ${demo} ${demo2})
+# list(REMOVE_ITEM sources ${demo} ${demo2})
 
-file(GLOB_RECURSE analysis package_analysis/*.cpp)
-file(GLOB_RECURSE bgs package_bgs/*.cpp package_bgs/*.c)
+file(GLOB_RECURSE analysis_src package_analysis/*.cpp)
+file(GLOB_RECURSE bgs_src package_bgs/*.cpp package_bgs/*.c)
 file(GLOB_RECURSE bgs_include package_bgs/*.h)
 
 # GMG is not available in older OpenCV versions
 if(${OpenCV_VERSION} VERSION_LESS 2.4.3)
-  file(GLOB gmg package_bgs/GMG.cpp)
-  list(REMOVE_ITEM bgs ${gmg})
+	file(GLOB gmg package_bgs/GMG.cpp)
+	list(REMOVE_ITEM bgs_src ${gmg})
 endif()
 
 include_directories(${CMAKE_SOURCE_DIR})
 
-add_library(bgs SHARED ${sources} ${bgs} ${analysis})
-target_link_libraries(bgs ${OpenCV_LIBS})
-set_property(TARGET bgs PROPERTY PUBLIC_HEADER ${bgs_include})
+add_library(libbgs STATIC ${sources} ${bgs_src} ${analysis_src})
+target_link_libraries(libbgs ${OpenCV_LIBS})
+set_property(TARGET libbgs PROPERTY PUBLIC_HEADER ${bgs_include})
+if(WIN32)
+	# set_property(TARGET libbgs PROPERTY SUFFIX ".lib")
+else()
+	set_property(TARGET libbgs PROPERTY OUTPUT_NAME "bgs")
+endif()
 
-add_executable(bgs_bin ${main})
-target_link_libraries(bgs_bin ${OpenCV_LIBS} bgs)
-set_target_properties(bgs_bin
-  PROPERTIES OUTPUT_NAME bgs)
+add_executable(bgslibrary ${main})
+target_link_libraries(bgslibrary ${OpenCV_LIBS} libbgs)
+# set_target_properties(bgslibrary PROPERTIES OUTPUT_NAME bgs)
 
 add_executable(bgs_demo ${demo})
-target_link_libraries(bgs_demo ${OpenCV_LIBS} bgs)
+target_link_libraries(bgs_demo ${OpenCV_LIBS} libbgs)
 
 add_executable(bgs_demo2 ${demo2})
-target_link_libraries(bgs_demo2 ${OpenCV_LIBS} bgs)
-
-INSTALL(TARGETS bgs
-	bgs_bin
-  RUNTIME DESTINATION bin COMPONENT app
-  LIBRARY DESTINATION lib COMPONENT runtime
-  ARCHIVE DESTINATION lib COMPONENT runtime
-  PUBLIC_HEADER DESTINATION include/package_bgs COMPONENT dev
-  FRAMEWORK DESTINATION "/Library/Frameworks"
+target_link_libraries(bgs_demo2 ${OpenCV_LIBS} libbgs)
+
+INSTALL(TARGETS libbgs
+	bgslibrary
+	RUNTIME DESTINATION bin COMPONENT app
+	LIBRARY DESTINATION lib COMPONENT runtime
+	ARCHIVE DESTINATION lib COMPONENT runtime
+	PUBLIC_HEADER DESTINATION include/package_bgs COMPONENT dev
+	FRAMEWORK DESTINATION "/Library/Frameworks"
 )
diff --git a/README_CMAKE_USERS.txt b/README_CMAKE_USERS.txt
index 9e4a680ddbf8e9638a8760a351dcb18ef99aef77..974e9416be37091a476b1c2f8421cb0e0e561097 100644
--- a/README_CMAKE_USERS.txt
+++ b/README_CMAKE_USERS.txt
@@ -1,14 +1,14 @@
 -------------------------------------------------
 -------------- WINDOWS CMAKE USERS --------------
 
-How to build BGSLibrary with OpenCV 2.4.10 and Visual Studio 2010 from CMAKE.
+How to build BGSLibrary with OpenCV 2.4.10 and Visual Studio 2013 from CMAKE.
 
 For Linux users, please see the instruction in README_LINUX_USERS.txt file.
 
 Dependencies:
 * GIT (tested with git version 2.7.2.windows.1).
 * CMAKE for Windows (tested with cmake version 3.1.1).
-* Microsoft Visual Studio (tested with VS2015).
+* Microsoft Visual Studio (tested with VS2013).
 
 Please follow the instructions below:
 
@@ -24,59 +24,54 @@ e.g.: C:\bgslibrary\build>_
 e.g.:
 \> setlocal
 \> set OpenCV_DIR=C:\OpenCV2.4.10\build
-\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 10" ..
+\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 12" ..
 or:
-\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 10 Win64" ..
+\> cmake -DOpenCV_DIR=%OpenCV_DIR% -G "Visual Studio 12 Win64" ..
 
-Now, you will see something like:
+Now, you will see something like (for win64):
 -------------------------------------------------
-C:\bgslibrary\build>cmake -DOpenCV_DIR=C:\OpenCV2.4.10\build -G "Visual Studio 10" ..
--- The C compiler identification is MSVC 16.0.40219.1
--- The CXX compiler identification is MSVC 16.0.40219.1
--- Check for working C compiler using: Visual Studio 10 2010
--- Check for working C compiler using: Visual Studio 10 2010 -- works
+-- The C compiler identification is MSVC 18.0.40629.0
+-- The CXX compiler identification is MSVC 18.0.40629.0
+-- Check for working C compiler using: Visual Studio 12 2013 Win64
+-- Check for working C compiler using: Visual Studio 12 2013 Win64 -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
--- Check for working CXX compiler using: Visual Studio 10 2010
--- Check for working CXX compiler using: Visual Studio 10 2010 -- works
+-- Check for working CXX compiler using: Visual Studio 12 2013 Win64
+-- Check for working CXX compiler using: Visual Studio 12 2013 Win64 -- works
 -- Detecting CXX compiler ABI info
 -- Detecting CXX compiler ABI info - done
--- OpenCV ARCH: x86
--- OpenCV RUNTIME: vc10
+-- Detecting CXX compile features
+-- Detecting CXX compile features - done
+-- OpenCV ARCH: x64
+-- OpenCV RUNTIME: vc12
 -- OpenCV STATIC: OFF
--- Found OpenCV 2.4.10 in C:/OpenCV2.4.10/build/x86/vc10/lib
--- You might need to add C:\OpenCV2.4.10\build\x86\vc10\bin to your PATH to be able to run your appl
-ications.
+-- Found OpenCV 2.4.10 in C:/OpenCV2.4.10/build/x64/vc12/lib
+-- You might need to add C:\OpenCV2.4.10\build\x64\vc12\bin to your PATH to be able to run your applications.
 -- Configuring done
 -- Generating done
--- Build files have been written to: E:/GitHubbkp2/bgslibrary_opencv2/build
-C:\bgslibrary\build>
+-- Build files have been written to: C:/bgslibrary/build
 -------------------------------------------------
 
 3) Include OpenCV binaries in the system path:
-\> set PATH=%PATH%;%OpenCV_DIR%\x86\vc10\bin
+\> set PATH=%PATH%;%OpenCV_DIR%\x86\vc12\bin
 or:
-\> set PATH=%PATH%;%OpenCV_DIR%\x64\vc10\bin
+\> set PATH=%PATH%;%OpenCV_DIR%\x64\vc12\bin
 
 4) Open 'bgs.sln' in Visual Studio and switch to 'RELEASE' mode 
-4.1) Note if you are using a Visual Studio version superior than 10, you will need to CANCEL the project wizard update. However, you can go to step (2) and change the Visual Studio version, e.g.: -G "Visual Studio XXX", where XXX is your Visual Studio version.
+4.1) Note if you are using a Visual Studio version superior than 2013, you will need to CANCEL the project wizard update. However, you can go to step (2) and change the Visual Studio version, e.g.: -G "Visual Studio XX", where XX is your Visual Studio version.
 
-5) Click on 'bgs' project, and set:
-[Configuration Type] Static library (.lib)
-[Target Extension] .lib
+5) Click on 'ALL_BUILD' project and build!
 
-6) Click on 'ALL_BUILD' project and build!
+6) If everything goes well, you can run bgslibrary in the Windows console as follows:
 
-7) If everything goes well, you can run bgslibrary in the Windows console as follows:
+6.1) Running BGSLibrary with a webcamera:
+C:\bgslibrary> build\bgslibrary.exe --use_cam --camera=0
 
-7.1) Running BGSLibrary with a webcamera:
-C:\bgslibrary> build\Release\bgs.exe --use_cam --camera=0
+6.2) Running demo code:
+C:\bgslibrary> build\bgs_demo.exe dataset/video.avi
 
-7.2) Running demo code:
-C:\bgslibrary> build\Release\bgs_demo.exe dataset/video.avi
-
-7.3) Running demo2 code:
-C:\bgslibrary> build\Release\bgs_demo2.exe
+6.3) Running demo2 code:
+C:\bgslibrary> build\bgs_demo2.exe
 
 Additional information:
 * Note that bgslibrary requires a 'config' folder in the working directory.
diff --git a/run_camera.sh b/run_camera.sh
index f000519fdbe3b6a6d9c0b38d8a08e55ecdee364b..7e8abe5b6a758611c5f58212e86dfe5353a69c16 100644
--- a/run_camera.sh
+++ b/run_camera.sh
@@ -1,3 +1,2 @@
 #!/bin/bash
-./build/bgs --use_cam --camera=0
-
+./build/bgslibrary --use_cam --camera=0
diff --git a/run_demo.bat b/run_demo.bat
new file mode 100644
index 0000000000000000000000000000000000000000..216799f8900d773d549911bf38cd3912852c8696
--- /dev/null
+++ b/run_demo.bat
@@ -0,0 +1,3 @@
+@echo off
+cls
+build\bgs_demo.exe dataset/video.avi
\ No newline at end of file
diff --git a/run_demo.sh b/run_demo.sh
index e734f061f62f56b7d0877bb63bbaa243d2762359..2a7777d5e5b066801a5796ef97c1f897fe72cc86 100644
--- a/run_demo.sh
+++ b/run_demo.sh
@@ -1,3 +1,2 @@
 #!/bin/bash
 ./build/bgs_demo dataset/video.avi
-
diff --git a/run_demo2.bat b/run_demo2.bat
new file mode 100644
index 0000000000000000000000000000000000000000..c7aba15dc94e81110847b01d69cc0e774d4a4207
--- /dev/null
+++ b/run_demo2.bat
@@ -0,0 +1,3 @@
+@echo off
+cls
+build\bgs_demo2.exe
\ No newline at end of file
diff --git a/run_demo2.sh b/run_demo2.sh
new file mode 100644
index 0000000000000000000000000000000000000000..910099c2d147bed6ea5622d00b54dbfa7a13ed29
--- /dev/null
+++ b/run_demo2.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+./build/bgs_demo2
diff --git a/run_video.sh b/run_video.sh
index 0ae1bcb7b9f036e44010800a5133ed6896fbbc42..38d86d98f7454f069ffdc40df2fb73f7660b9d47 100644
--- a/run_video.sh
+++ b/run_video.sh
@@ -1,3 +1,2 @@
 #!/bin/bash
-./build/bgs -uf -fn=dataset/video.avi
-
+./build/bgslibrary -uf -fn=dataset/video.avi