diff --git a/Application/CMakeLists.txt b/Application/CMakeLists.txt
index 8cce3392b8a21495e1bb1c570624438b2f4f9d8c..dc58d6877689f820196f5e0e091e69ad06075f5d 100644
--- a/Application/CMakeLists.txt
+++ b/Application/CMakeLists.txt
@@ -198,16 +198,13 @@ if(TREX_ENABLE_CPP20)
 endif()
 
 if(CMAKE_COMPILER_IS_GNUCXX)
-set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic -Wall -Wextra -Wno-long-long -ggdb -DOM_DEBUG -O0 -march='haswell' -no-pie")
-set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march='haswell' -g0 -no-pie")
-set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -march='haswell' -ggdb -no-pie")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-pie -fPIC -march='haswell'")
-set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
-set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 -ggdb")
-set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pedantic -Wall -Wextra -Wno-long-long -ggdb -DOM_DEBUG -O0")
-#if(APPLE)
-#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -isystem ")
-#endif()
+    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -pedantic -Wall -Wextra -Wno-long-long -ggdb -DOM_DEBUG -O0 -march='haswell' -no-pie")
+    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -march='haswell' -g0 -no-pie")
+    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3 -march='haswell' -ggdb -no-pie")
+    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -no-pie -fPIC -march='haswell'")
+    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O3")
+    set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -O3 -ggdb")
+    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -pedantic -Wall -Wextra -Wno-long-long -ggdb -DOM_DEBUG -O0")
 endif()
 
 if(XCODE)
@@ -230,10 +227,8 @@ if(XCODE)
     set(CMAKE_XCODE_ATTRIBUTE_CLANG_WARN_CONSTANT_CONVERSION "YES")
     set(CMAKE_XCODE_ATTRIBUTE_GCC_WARN_NON_VIRTUAL_DESTRUCTOR "YES")
 endif()
-#endif()
-
- set(trex_subproject_CMAKE_ARGS "")
 
+set(trex_subproject_CMAKE_ARGS "")
 
 SET(trex_subproject_CMAKE_ARGS ${trex_subproject_CMAKE_ARGS}
     "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
diff --git a/Application/src/ProcessedVideo/pv.cpp b/Application/src/ProcessedVideo/pv.cpp
index 8a576939fbb7f98bca76af9c7592fd8f8c3d1b80..ef854de7a8c5391030a9786cd36abc0d768a202e 100644
--- a/Application/src/ProcessedVideo/pv.cpp
+++ b/Application/src/ProcessedVideo/pv.cpp
@@ -161,14 +161,27 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         // declared outside so memory doesnt have to be freed/allocated all the time
         static DataPackage pixels;
         static std::vector<Header::line_type> mask((NoInitializeAllocator<Header::line_type>()));
+        static std::vector<LegacyShortHorizontalLine> mask_legacy((NoInitializeAllocator<LegacyShortHorizontalLine>()));
         
         for(int i=0; i<_n; i++) {
             uint16_t start_y, mask_size;
             ptr->read<uint16_t>(start_y);
             ptr->read<uint16_t>(mask_size);
-            mask.resize(mask_size);
             
-            ptr->read_data(mask_size * ref.header().line_size, (char*)mask.data());
+            if(ref.header().version < V_7) {
+                mask_legacy.resize(mask_size);
+                mask.clear();
+                mask.reserve(mask_legacy.size());
+                
+                assert(ref.header().line_size == sizeof(LegacyShortHorizontalLine));
+                
+                ptr->read_data(mask_size * ref.header().line_size, (char*)mask_legacy.data());
+                std::copy(mask_legacy.begin(), mask_legacy.end(), std::back_inserter(mask));
+                
+            } else {
+                mask.resize(mask_size);
+                ptr->read_data(mask_size * ref.header().line_size, (char*)mask.data());
+            }
             
             uint64_t num_pixels = 0;
             for(auto &l : mask) {
@@ -186,7 +199,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
                 for (auto &l : *uncompressed) {
                     for (int x=l.x0; x<=l.x1; x++) {
                         auto &p = ptr[idx++];
-                        p = min(UCHAR_MAX, max(0, int(ref.average().at<uchar>(l.y, x)) - p));
+                        p = (uchar)saturate(int(ref.average().at<uchar>(l.y, x)) - int(p));
                     }
                 }
             }
@@ -274,8 +287,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
             auto ptr = full_image.ptr(line_ptr->y, line_ptr->x0);
             assert(line_ptr->x1 >= line_ptr->x0);
             long_t N = long_t(line_ptr->x1) - long_t(line_ptr->x0) + 1;
-            assert(N > 0);
-            memcpy(pixel_ptr, ptr, N);
+            memcpy(pixel_ptr, ptr, sign_cast<size_t>(N));
             pixel_ptr += N;
         }
         
@@ -307,7 +319,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         pack.write(_timestamp); // force uint32_t because it should have been turned
         pack.write(_n);         // into a relative timestamp by now // V_4 use uint64_t anyway
         
-        for(int i=0; i<_n; i++) {
+        for(uint16_t i=0; i<_n; i++) {
             auto &mask = _mask.at(i);
             auto &pixels = _pixels.at(i);
             
@@ -361,7 +373,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         ref.read<std::string>(version_str);
         
         if(version_str.length() > 2) {
-            uchar nr = version_str.at(version_str.length()-1) - '0';
+            auto nr = version_str.at(version_str.length()-1u) - uchar('0');
             version = (Version)(nr-1);
             
         } else {
@@ -413,7 +425,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         if(average)
             delete average;
         
-        average = new Image(this->resolution.height, this->resolution.width, channels);
+        average = new Image((uint)this->resolution.height, (uint)this->resolution.width, channels);
         _average_offset = ref.current_offset();
         ref.read_data(average->size(), (char*)average->data());
         
@@ -426,7 +438,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
             ref.read<uint64_t>(mask_size);
             if(mask_size) {
                 // does it use a mask?
-                mask = new Image(this->resolution.height /*- (offsets.y + offsets.height)*/, this->resolution.width /*- (offsets.x + offsets.width)*/, channels);
+                mask = new Image((uint)this->resolution.height /*- (offsets.y + offsets.height)*/, (uint)this->resolution.width /*- (offsets.x + offsets.width)*/, channels);
                 
                 //Debug("Reading mask with %dx%d", mask->cols, mask->rows);
                 ref.read_data(mask->size(), (char*)mask->data());
@@ -510,12 +522,12 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         _index_offset = ref.write(decltype(index_offset)(0));
         _timestamp_offset = ref.write(timestamp);
         
-        ref.write<std::string>(file::Path(name).filename().to_string());
+        ref.write<std::string>((std::string)file::Path(name).filename());
         
         if(average)
             _average_offset = ref.write_data(average->size(), (char*)average->data());
         else {
-            Image tmp(resolution.height, resolution.width, 1);
+            Image tmp((uint)resolution.height, (uint)resolution.width, 1);
             _average_offset = ref.write_data(tmp.size(), (char*)tmp.data());
         }
         
@@ -603,7 +615,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         std::chrono::microseconds ns_l, ns_e;
         
         if(!_open_for_writing){
-            uint64_t idx = length() * 0.5;
+            uint64_t idx = length() / 2u;
             uint64_t edx = length()-1;
             if(idx < length()) {
                 pv::Frame lastframe;
@@ -652,7 +664,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
     
     void File::set_start_time(std::chrono::time_point<std::chrono::system_clock> tp) {
         assert(!open());
-        _header.timestamp = std::chrono::time_point_cast<std::chrono::microseconds>(tp).time_since_epoch().count();
+        _header.timestamp = narrow_cast<uint64_t>(std::chrono::time_point_cast<std::chrono::microseconds>(tp).time_since_epoch().count());
     }
     
     const pv::Frame& File::last_frame() {
@@ -708,7 +720,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
                     
                     _compression_value = _compression_value + size / float(in_len);
                     _compression_samples ++;
-                    _compression_ratio = _compression_value / float(_compression_samples);
+                    _compression_ratio = _compression_value / double(_compression_samples);
                 }
                 
                 if(size < in_len) {
@@ -790,7 +802,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         else
             output = cv::Mat::zeros(header().resolution.height, header().resolution.width, CV_8UC1);
         
-        for (int i=0; i<frame.n(); i++) {
+        for (uint16_t i=0; i<frame.n(); i++) {
             uint64_t index = 0;
             auto &mask = frame.mask().at(i);
             auto &pixels = frame.pixels().at(i);
@@ -937,7 +949,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         uint64_t start_frame = 0;
         std::set<long_t> samples;
         while(timer.elapsed() < 1 && pixel_values.size() < 10000000 && start_frame < length()) {
-            auto range = arange<long_t>((long_t)start_frame, (long_t)length(), max(1, (long_t)length() * 0.1));
+            auto range = arange<long_t>((long_t)start_frame, (long_t)length(), max(1, long_t(length() * 0.1)));
             pv::Frame frame;
             uint64_t big_loop_size = samples.size();
             
@@ -950,7 +962,7 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
                 if(samples.size() == prev_size)
                     continue;
                 
-                read_frame(frame, frameIndex);
+                read_frame(frame, (uint64_t)frameIndex);
                 for(uint64_t i=0; i<frame.n(); ++i) {
                     pixel_values.insert(frame.pixels().at(i)->begin(), frame.pixels().at(i)->end());
                 }
@@ -974,12 +986,12 @@ lzo_align_t __LZO_MMODEL var [ ((size) + (sizeof(lzo_align_t) - 1)) / sizeof(lzo
         return p;
     }
     
-    uint64_t File::generate_average_tdelta() {
-        if(!_open_for_writing && _header.average_tdelta == 0) {
+    double File::generate_average_tdelta() {
+        if(!_open_for_writing && _header.average_tdelta == 0 && length()>0) {
             // readable
             double average = 0;
             uint64_t samples = 0;
-            const uint64_t step = max(1, (length()-1) * 0.1);
+            const uint64_t step = max(1u, (length()-1) / 10u);
             pv::Frame frame;
             for (uint64_t i=1; i<length(); i+=step) {
                 read_frame(frame, i);
diff --git a/Application/src/ProcessedVideo/pv.h b/Application/src/ProcessedVideo/pv.h
index 7ba73d9007a8b63e2a5205c59abbf2002bd4dc02..7a2c7cb9a6a026c5cfece53b76956c8ba3e08be9 100644
--- a/Application/src/ProcessedVideo/pv.h
+++ b/Application/src/ProcessedVideo/pv.h
@@ -12,6 +12,43 @@ namespace pv {
     using namespace cmn;
     class File;
     class Blob;
+
+    struct LegacyShortHorizontalLine {
+    private:
+        //! starting and end position on x
+        //  the last bit of _x1 is a flag telling the program
+        //  whether this line is the last line on the current y coordinate.
+        //  the following lines are on current_y + 1.
+        uint16_t _x0 = 0, _x1 = 0;
+        
+    public:
+        //! compresses an array of HorizontalLines to an array of ShortHorizontalLines
+        static std::vector<LegacyShortHorizontalLine> compress(const std::vector<cmn::HorizontalLine>& lines);
+        //! uncompresses an array of ShortHorizontalLines back to HorizontalLines
+        static std::shared_ptr<std::vector<cmn::HorizontalLine>> uncompress(uint16_t start_y, const std::vector<LegacyShortHorizontalLine>& compressed);
+        
+    public:
+        constexpr LegacyShortHorizontalLine() {}
+        
+        constexpr LegacyShortHorizontalLine(uint16_t x0, uint16_t x1, bool eol = false)
+            : _x0(x0), _x1(uint16_t(x1 << 1) + uint16_t(eol))
+        {
+            assert(x1 < 32768); // MAGIC NUMBERZ (uint16_t - 1 bit)
+        }
+        
+        constexpr uint16_t x0() const { return _x0; }
+        constexpr uint16_t x1() const { return (_x1 & 0xFFFE) >> 1; }
+        
+        //! returns true if this is the last element on the current y coordinate
+        //  if true, the following lines are on current_y + 1.
+        //  @note stored in the last bit of _x1
+        constexpr bool eol() const { return _x1 & 0x1; }
+        void eol(bool v) { _x1 = v ? (_x1 | 0x1) : (_x1 & 0xFFFE); }
+        
+        constexpr operator pv::ShortHorizontalLine() const {
+            return pv::ShortHorizontalLine(x0(), x1(), eol());
+        }
+    };
     
     enum Version {
         V_1 = 0,
@@ -37,7 +74,10 @@ namespace pv {
          */
         V_6,
         
-        current = V_6
+        /** Changed format of ShortHorizontalLine */
+        V_7,
+        
+        current = V_7
     };
     
     class Frame : public IndexedDataTransport {
@@ -177,7 +217,7 @@ namespace pv {
         uint64_t _prev_frame_time;
         
         // debug compression
-        GETTER(std::atomic<float>, compression_ratio)
+        GETTER(std::atomic<double>, compression_ratio)
         double _compression_value;
         uint32_t _compression_samples;
         
@@ -274,7 +314,7 @@ namespace pv {
         virtual uint64_t timestamp(uint64_t) const override;
         virtual uint64_t start_timestamp() const override;
         virtual short framerate() const override;
-        uint64_t generate_average_tdelta();
+        double generate_average_tdelta();
         
         UTILS_TOSTRING("pv::File<V" << _header.version+1 << ", " << filesize() << ", '" << filename() << "', " << _header.resolution << ", " << _header.num_frames << " frames, "<< (_header.mask ? "with mask" : "no mask") << ">");
         
@@ -297,7 +337,7 @@ namespace pv {
             uint64_t fps_l = 0;
             
             if(!_open_for_writing){
-                uint64_t idx = length() * 0.5;
+                uint64_t idx = length() / 2u;
                 //uint64_t edx = length()-1;
                 if(idx < length()) {
                     pv::Frame lastframe;
diff --git a/Application/src/commons/common/commons.pc.h b/Application/src/commons/common/commons.pc.h
index 074f7d4b13f6cff84f7f5ba08af95d6f4adbe1f8..7fadfadfdd1fb365a8f5e92ad4da22b3ace5598f 100644
--- a/Application/src/commons/common/commons.pc.h
+++ b/Application/src/commons/common/commons.pc.h
@@ -1,5 +1,14 @@
 #pragma once
 
+#pragma warning(push, 0)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wall"
+#pragma clang diagnostic ignored "-Wextra"
+#pragma clang diagnostic ignored "-Wsign-conversion"
+#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
+#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
+#pragma clang diagnostic ignored "-Wfloat-conversion"
+
 #ifdef WIN32
 #include <windows.h>
 #endif
@@ -72,3 +81,7 @@ typedef int32_t long_t;
 #include <commons/common/cpputils/utilsexception.h>
 #include <commons/common/cpputils/debug/Printable.h>
 #include <cnpy.h>
+
+// Code that produces warnings...
+#pragma clang diagnostic pop
+#pragma warning(pop)
diff --git a/Application/src/commons/common/file/DataFormat.cpp b/Application/src/commons/common/file/DataFormat.cpp
index a20b996f5a5e6c4929a3eef44606cf15fb8c79c1..6ed1a711fcfbdcb7b14ae0a18b9486b1b60ea450 100644
--- a/Application/src/commons/common/file/DataFormat.cpp
+++ b/Application/src/commons/common/file/DataFormat.cpp
@@ -198,7 +198,7 @@ void DataFormat::start_reading() {
     if ((fd = ::open(_filename.c_str(), O_RDONLY)) == -1)
         U_EXCEPTION("Cannot open file '%S'.", &_filename);
 
-    if ((_data = (char*)mmap((caddr_t)0, sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t)(-1))
+    if ((_data = (char*)mmap((caddr_t)0, (size_t)sbuf.st_size, PROT_READ, MAP_SHARED, fd, 0)) == (caddr_t)(-1))
         U_EXCEPTION("Cannot mmap file '%S'.", &_filename);
 #endif
     _supports_fast = true;
@@ -336,7 +336,7 @@ uint64_t Data::write(const std::string& val) {
 template<>
 void Data::read(std::string& str) {
     std::stringstream ss;
-    uchar c = -1;
+    uchar c = UCHAR_MAX;
     while (c != 0) {
         read<uchar>(c);
         //read_data(1, (char*)&c);
diff --git a/Application/src/commons/common/file/DataFormat.h b/Application/src/commons/common/file/DataFormat.h
index 95bed63201542f08527d8d67a23574090745be96..9c4b38fbc90fac10d7b61325c9d289f09925f533 100644
--- a/Application/src/commons/common/file/DataFormat.h
+++ b/Application/src/commons/common/file/DataFormat.h
@@ -229,7 +229,7 @@ namespace cmn {
         const file::Path& filename() const { return _filename; }
         const std::string& project_name() const { return _project_name; }
         
-        long read_size() const { if(!_mmapped) U_EXCEPTION("Must be mmapped."); return _reading_file_size; }
+        //long read_size() const { if(!_mmapped) U_EXCEPTION("Must be mmapped."); return _reading_file_size; }
 		uint64_t current_offset() const;
 		virtual uint64_t tell() const override;
         
diff --git a/Application/src/commons/common/file/Path.cpp b/Application/src/commons/common/file/Path.cpp
index bb21c5ee284c16170427509b5de6fa37ad31ad42..26a64e48dd0f445e3acd311e3d04f286a1a1ea4c 100644
--- a/Application/src/commons/common/file/Path.cpp
+++ b/Application/src/commons/common/file/Path.cpp
@@ -25,6 +25,8 @@
 #include <filesystem>
 #endif
 
+#include <misc/metastring.h>
+
 namespace file {
     char Path::os_sep() { return OS_SEP; }
     
@@ -42,8 +44,8 @@ namespace file {
         : Path(std::string(c))
     {}
 
-    Path::Path(string_view sv)
-        : Path(sv.to_string())
+    Path::Path(std::string_view sv)
+        : Path(std::string(sv))
     {}
 
     Path& Path::operator/=(const Path &other) {
@@ -59,14 +61,14 @@ namespace file {
 #endif
     }
 
-    string_view Path::filename() const {
+std::string_view Path::filename() const {
         if(empty())
             return _str;
         
         const char *ptr = _str.data() + _str.length() - 1;
         for(; ptr >= _str.data(); ptr--) {
             if(*ptr == OS_SEP)
-                return string_view(ptr+1, _str.data() + _str.length() - (ptr+1));
+                return std::string_view(ptr+1u, size_t(_str.data() + _str.length() - (ptr+1u)));
         }
         
         return _str;
@@ -88,11 +90,11 @@ namespace file {
         if(count != position+1)
             U_EXCEPTION("Path only contains %d segments (requested split at %d).", count, position);
         
-        return {Path(string_view(_str.data(), before_len)), Path(string_view(_str.data() + before_len, _str.length() - before_len))};
+        return {Path(std::string_view(_str.data(), before_len)), Path(std::string_view(_str.data() + before_len, _str.length() - before_len))};
     }
 
     Path Path::remove_filename() const {
-        return Path(string_view(_str.data(), _str.length() - filename().length()).to_string());
+        return Path(std::string_view(_str.data(), _str.length() - filename().length()));
     }
 
     Path operator/(const Path& lhs, const Path& rhs) {
@@ -100,7 +102,7 @@ namespace file {
     }
 
     Path operator+(const Path& lhs, const Path& rhs) {
-        return Path(lhs.str() + OS_SEP + rhs.str());
+        return Path(lhs.str() + rhs.str());
     }
 
     bool Path::exists() const {
@@ -121,22 +123,22 @@ namespace file {
         struct stat sbuf;
         if (stat(c_str(), &sbuf) == -1)
             U_EXCEPTION("Cannot stat file '%S'.", &str());
-        return sbuf.st_size;
+        return narrow_cast<uint64_t>(sbuf.st_size);
 #endif
     }
 
-    string_view Path::extension() const {
+    std::string_view Path::extension() const {
         if(empty())
-            return string_view(_str);
+            return std::string_view(_str);
         
         const char *ptr = &_str.back();
         for(; ptr != _str.data(); --ptr) {
             if (*ptr == '.') {
-                return string_view(ptr+1, &_str.back() - ptr);
+                return std::string_view(ptr+1, size_t(&_str.back() - ptr));
             }
         }
         
-        return string_view(_str.data() + _str.length() - 1, 0);
+        return std::string_view(_str.data() + _str.length() - 1, 0);
     }
     
     bool Path::has_extension() const {
@@ -244,7 +246,7 @@ namespace file {
             
             auto extensions = utils::split(utils::lowercase(filter_extension), ';');
             if(path.has_extension()) {
-                return contains(extensions, path.extension().to_string());
+                return contains(extensions, path.extension());
             }
             
             return false;
@@ -276,15 +278,15 @@ namespace file {
         return result;
     }
 
-    Path Path::replace_extension(string_view ext) const {
-        string_view e = extension();
-        return string_view(_str.data(), max(0, e.data() - _str.data() - 1)).to_string() + "." + ext.to_string();
+    Path Path::replace_extension(std::string_view ext) const {
+        auto e = extension();
+        return std::string_view(_str.data(), size_t(max(0, e.data() - _str.data() - 1))) + "." + ext;
     }
 
-    Path Path::add_extension(string_view ext) const {
+    Path Path::add_extension(std::string_view ext) const {
         auto current = extension();
         if(ext != current)
-            return Path(_str + "." + ext.to_string());
+            return Path(_str + "." + ext);
         return *this;
     }
     
diff --git a/Application/src/commons/common/file/Path.h b/Application/src/commons/common/file/Path.h
index c488d03a658dcc5986e09db0b7f603b3793b898d..27fad2713148fec9ab828664f3c44428ebed6b7e 100644
--- a/Application/src/commons/common/file/Path.h
+++ b/Application/src/commons/common/file/Path.h
@@ -2,7 +2,7 @@
 #define _PATH_H
 
 #include <types.h>
-#include <misc/string_view.h>
+#include <string_view>
 
 namespace file {
     using namespace cmn;
@@ -15,7 +15,7 @@ namespace file {
     public:
         Path(const std::string& s = "");
         Path(const char* c);
-        Path(string_view sv);
+        Path(std::string_view sv);
         
         const char* c_str() const { return _str.c_str(); }
         
@@ -29,7 +29,7 @@ namespace file {
         bool empty() const { return _str.empty(); }
         
         //! Returns the last filename, removes the path
-        string_view filename() const;
+        std::string_view filename() const;
         
         //! Returns path, removes last filename
         Path remove_filename() const;
@@ -64,14 +64,14 @@ namespace file {
         //! Moves the file to given destination
         bool move_to(const file::Path& to);
         
-        Path replace_extension(string_view ext) const;
-        Path add_extension(string_view ext) const;
+        Path replace_extension(std::string_view ext) const;
+        Path add_extension(std::string_view ext) const;
         bool has_extension() const;
         Path remove_extension() const;
         
         FILE* fopen(const std::string& access_rights) const;
         
-        string_view extension() const;
+        std::string_view extension() const;
         
         bool operator<(const Path& other) const;
         bool operator<=(const Path& other) const;
diff --git a/Application/src/commons/common/gui/DrawBase.cpp b/Application/src/commons/common/gui/DrawBase.cpp
index b213aa205c157dab46672f18657e501cfa743e4b..e6b8153c46d571875b784060169e00a4302894c4 100644
--- a/Application/src/commons/common/gui/DrawBase.cpp
+++ b/Application/src/commons/common/gui/DrawBase.cpp
@@ -1,4 +1,5 @@
 #include "DrawBase.h"
+#include <misc/metastring.h>
 
 namespace gui {
     Base *_latest_base = nullptr;
@@ -7,7 +8,7 @@ namespace gui {
 
     std::function<uint32_t(const Font&)> line_spacing_fn = [](const Font& font) -> uint32_t
     {
-        return roundf(25 * font.size);
+        return narrow_cast<uint32_t>(roundf(25 * font.size));
     };
     void Base::set_default_line_spacing(std::function<uint32_t(const Font&)> fn) {
         line_spacing_fn = fn;
@@ -17,7 +18,7 @@ namespace gui {
     }
 
     std::function<Bounds(const std::string&, Drawable*, const Font&)> text_bounds_fn = [](const std::string& text, Drawable*, const Font& font) -> Bounds {
-        return Bounds(0, 0, text.length() * 11.3 * font.size, line_spacing_fn(font));
+        return Bounds(0, 0, text.length() * 11.3f * font.size, line_spacing_fn(font));
     };
     Bounds Base::default_text_bounds(const std::string &text, Drawable* obj, const Font& font) {
         return text_bounds_fn(text, obj, font);
@@ -26,6 +27,19 @@ namespace gui {
         text_bounds_fn = fn;
     }
 
+    uint32_t Base::line_spacing(const Font& font) {
+        return narrow_cast<uint32_t>(roundf(25 * font.size));
+    }
+    float Base::text_width(const Text &text) const {
+        return text.txt().length() * 8.5f * text.font().size;
+    }
+    float Base::text_height(const Text &text) const {
+        return 18.f * text.font().size;
+    }
+    Bounds Base::text_bounds(const std::string& text, Drawable*, const Font& font) {
+        return Bounds(0, 0, text.length() * 11.3f * font.size, 26.f * font.size);
+    }
+
     Base::Base() {
         _previous_base = _latest_base;
         _previous_line_spacing = line_spacing_fn;
@@ -50,11 +64,11 @@ namespace gui {
             
             _restore_line_spacing = [](const Font& font) -> uint32_t
                 {
-                    return roundf(25 * font.size);
+                    return narrow_cast<uint32_t>(roundf(25 * font.size));
                 };
             _restore_line_bounds = [](const std::string& text, Drawable*, const Font& font) -> Bounds
                 {
-                    return Bounds(0, 0, text.length() * 11.3 * font.size, line_spacing_fn(font));
+                    return Bounds(0, 0, text.length() * 11.3f * font.size, line_spacing_fn(font));
                 };
             
             _latest_base = _previous_base;
diff --git a/Application/src/commons/common/gui/DrawBase.h b/Application/src/commons/common/gui/DrawBase.h
index 8823aebc7ffb48eb6c918fcbcb45350b707606c0..59a479e728ab30966ce0e9314b339f2951d144c1 100644
--- a/Application/src/commons/common/gui/DrawBase.h
+++ b/Application/src/commons/common/gui/DrawBase.h
@@ -44,27 +44,19 @@ namespace gui {
         virtual void set_title(std::string) = 0;
         virtual Size2 window_dimensions() { return Size2(-1); }
         
-        virtual float text_width(const Text &text) const {
-            return text.txt().length() * 8.5f * text.font().size;
-        }
-        virtual float text_height(const Text &text) const {
-            return 18.f * text.font().size;
-        }
+        virtual float text_width(const Text &text) const;
+        virtual float text_height(const Text &text) const;
         
         static inline Size2 text_dimensions(const std::string& text, Drawable* obj = NULL, const Font& font = Font()) {
             auto size = default_text_bounds(text, obj, font);
             return size.pos() + size.size();
         }
         
-        virtual Bounds text_bounds(const std::string& text, Drawable*, const Font& font) {
-            return Bounds(0, 0, text.length() * 11.3 * font.size, 26 * font.size);
-        }
+        virtual Bounds text_bounds(const std::string& text, Drawable*, const Font& font);
         static Bounds default_text_bounds(const std::string& text, Drawable* obj = NULL, const Font& font = Font());
         static void set_default_text_bounds(std::function<Bounds(const std::string&, Drawable*, const Font&)>);
         
-        virtual uint32_t line_spacing(const Font& font) {
-            return roundf(25 * font.size);
-        }
+        virtual uint32_t line_spacing(const Font& font);
         
         static uint32_t default_line_spacing(const Font& font);
         static void set_default_line_spacing(std::function<uint32_t(const Font&)>);
diff --git a/Application/src/commons/common/gui/DrawCVBase.cpp b/Application/src/commons/common/gui/DrawCVBase.cpp
index 96abdb55821d3a483d6643a07ce1e58e4c06eb1a..b25039b898683ee939fe13e4cda4a2a5637d349e 100644
--- a/Application/src/commons/common/gui/DrawCVBase.cpp
+++ b/Application/src/commons/common/gui/DrawCVBase.cpp
@@ -1,4 +1,5 @@
 #include "DrawCVBase.h"
+#include <misc/metastring.h>
 
 namespace gui {
     IMPLEMENT(CVBase::_static_pixels);
@@ -33,10 +34,10 @@ namespace gui {
                     uchar &r = *pixel++;
                     uchar &a = *pixel++;
                     
-                    b *= (color.b / 255.f);
-                    g *= (color.g / 255.f);
-                    r *= (color.r / 255.f);
-                    a *= (color.a / 255.f);
+                    b = (uchar)saturate(float(b) * (color.b / 255.f));
+                    g = (uchar)saturate(float(g) * (color.g / 255.f));
+                    r = (uchar)saturate(float(r) * (color.r / 255.f));
+                    a = (uchar)saturate(float(a) * (color.a / 255.f));
                 }
             }
         }
@@ -49,7 +50,7 @@ namespace gui {
         
         auto &pos = ptr->pos();
         if(pos.x + mat.cols <= _window.cols && pos.y + mat.rows <= _window.rows)
-            mat.copyTo(_window(cv::Rect(pos.x, pos.y, mat.cols, mat.rows)), split[3]);
+            mat.copyTo(_window(Bounds(pos.x, pos.y, mat.cols, mat.rows)), split[3]);
         
         else if(   pos.x < _window.cols
                 && pos.x + _window.cols >= 0
@@ -63,10 +64,10 @@ namespace gui {
             float mx = pos.x < 0 ? -pos.x : 0;
             float my = pos.y < 0 ? -pos.x : 0;
             
-            cv::Mat small = mat(cv::Rect(mx, my, w, h));
-            cv::Mat big = _window(cv::Rect(pos.x >= 0 ? pos.x : 0, pos.y >= 0 ? pos.y : 0, w, h));
+            cv::Mat small = mat(Bounds(mx, my, w, h));
+            cv::Mat big = _window(Bounds(pos.x >= 0 ? pos.x : 0, pos.y >= 0 ? pos.y : 0, w, h));
             
-            small.copyTo(big, split[3](cv::Rect(mx, my, w, h)));
+            small.copyTo(big, split[3](Bounds(mx, my, w, h)));
             
         } else {
             Debug("Didnt draw %f,%f %dx%d. (%dx%d) in window %dx%d", pos.x, pos.y, mat.cols, mat.rows, mat.cols, mat.rows, _window.cols, _window.rows);
@@ -111,7 +112,7 @@ namespace gui {
                 
             case Type::VERTICES: {
                 auto ptr = static_cast<Vertices*>(o);
-                float t = 1;
+                int t = 1;
                 if(dynamic_cast<Line*>(o))
                     t = max(1, min(static_cast<Line*>(o)->thickness(), CV_MAX_THICKNESS));
                 
@@ -164,7 +165,7 @@ namespace gui {
             case Type::CIRCLE: {
                 auto ptr = static_cast<Circle*>(o);
                 auto &color = ptr->color();
-                cv::circle(_window, (cv::Point2f)Vec2(ptr->pos()), ptr->radius(), cv::Scalar(color.b, color.g, color.r, color.a), 1
+                cv::circle(_window, (cv::Point2f)Vec2(ptr->pos()), narrow_cast<int>(ptr->radius()), cv::Scalar(color.b, color.g, color.r, color.a), 1
 #if CV_MAJOR_VERSION >= 3
                            , cv::LINE_AA
 #endif
diff --git a/Application/src/commons/common/gui/DrawStructure.cpp b/Application/src/commons/common/gui/DrawStructure.cpp
index e90dbc3feba8e783428409c31a0d855b3b78bfdc..c708c6c00a3028b881b8ea640582628667bf9941 100644
--- a/Application/src/commons/common/gui/DrawStructure.cpp
+++ b/Application/src/commons/common/gui/DrawStructure.cpp
@@ -26,8 +26,8 @@ namespace gui {
                 std::chrono::duration<float> d = std::chrono::system_clock::now() - last;
                 auto d_ = std::chrono::duration_cast<std::chrono::milliseconds>(d).count() / 1000.f;
                 
-                alpha -= 0.25 * d_;
-                clr.a = saturate(255 * alpha);
+                alpha -= 0.25f * d_;
+                clr.a = (uint8_t)saturate(255.f * alpha);
             }
             
             last = std::chrono::system_clock::now();
@@ -82,7 +82,7 @@ namespace gui {
             Vec2 pos = Vec2(width()-10, 0) + Vec2(0, 100).mul(scale().reciprocal());
             for (size_t i=min(size_t(20), error_messages.size()); i>0; i--) {
                 auto &e = error_messages.at(i-1);
-                auto t = text(e.msg, pos, e.clr, Font(0.6, Align::Right), scale().reciprocal());
+                auto t = text(e.msg, pos, e.clr, Font(0.6f, Align::Right), scale().reciprocal());
                 
                 //t->set_scale(Vec2(1/interface_scale));
                 
@@ -98,8 +98,8 @@ namespace gui {
     Dialog::Dialog(DrawStructure& d, const std::function<void(Result)>& callback, const std::string &text, const std::string& title, const std::string& okay, const std::string& abort, const std::string& second, const std::string& third, const std::string& fourth)
       : _closed(false),
         _title_bg(Bounds(), White.alpha(100)),
-        _text(std::make_shared<StaticText>(text, Vec2(250, 135), Size2(500, 50), Font(0.8))),
-        _title(title, Vec2(), White, Font(0.9, Style::Bold)),
+        _text(std::make_shared<StaticText>(text, Vec2(250, 135), Size2(500, 50), Font(0.8f))),
+        _title(title, Vec2(), White, Font(0.9f, Style::Bold)),
         _okay(std::make_shared<Button>(okay, Bounds())),
         _abort(abort.empty() ? nullptr : std::make_shared<Button>(abort, Bounds())),
         _second(second.empty() ? nullptr : std::make_shared<Button>(second, Bounds())),
@@ -113,8 +113,8 @@ namespace gui {
         if(!d.dialog_window_size().empty())
             size = d.dialog_window_size();
         
-        _title_bg.set_bounds(Bounds(5,10,max(650, min(900, size.width * 0.25)),60));
-        _okay->set_bounds(Bounds(Vec2(_title_bg.width() * 0.5, 230), Size2(100, 40)));
+        _title_bg.set_bounds(Bounds(5,10,max(650, min(900, size.width * 0.25f)),60));
+        _okay->set_bounds(Bounds(Vec2(_title_bg.width() * 0.5f, 230), Size2(100, 40)));
         if(_abort)
             _abort->set_bounds(Bounds(310, 230, 140, 40));
         if(_second)
@@ -144,7 +144,7 @@ namespace gui {
             buttons.push_back(_abort);
         _buttons->set_children(buttons);
         
-        set_background(DarkCyan.brighten(0.2).alpha(220), Black);
+        set_background(DarkCyan.brighten(0.2f).alpha(220), Black);
         
         _text->set_background(Transparent, Transparent);
         _title.set_origin(Vec2(0.5));
@@ -225,7 +225,7 @@ namespace gui {
         //d.wrap_object(*_text);
         d.wrap_object(_title);
         
-        _title.set_pos(_title_bg.size() * 0.5 + Vec2(0, _title_bg.height() * 0.2));
+        _title.set_pos(_title_bg.size() * 0.5f + Vec2(0, _title_bg.height() * 0.2f));
         
         _layout.set_policy(gui::VerticalLayout::Policy::CENTER);
         _buttons->set_policy(gui::HorizontalLayout::Policy::CENTER);
@@ -234,8 +234,8 @@ namespace gui {
         
         _layout.update();
         _text->update();
-        _layout.set_origin(Vec2(0.5, 0));
-        _layout.set_pos(Vec2(0.5 * width(), _layout.pos().y));
+        _layout.set_origin(Vec2(0.5f, 0));
+        _layout.set_pos(Vec2(0.5f * width(), _layout.pos().y));
         
         set_size(Size2(width(), _layout.height() + _layout.pos().y + 10));
         
diff --git a/Application/src/commons/common/gui/FileChooser.cpp b/Application/src/commons/common/gui/FileChooser.cpp
index 61415144769c7ea4e2e50bfc3dfa30095f43efa2..33b628972b54235ef81e30836a5bd6adc1797f8a 100644
--- a/Application/src/commons/common/gui/FileChooser.cpp
+++ b/Application/src/commons/common/gui/FileChooser.cpp
@@ -150,7 +150,7 @@ FileChooser::FileChooser(const file::Path& start, const std::string& extension,
     _graph->set_scale(_base.dpi_scale() * gui::interface_scale());
     _list->on_select([this](auto i, auto&path){ file_selected(i, path.path()); });
     
-    _button->set_font(gui::Font(0.6, Align::Center));
+    _button->set_font(gui::Font(0.6f, Align::Center));
     _button->on_click([this](auto){
         _running = false;
         _confirmed_file = _selected_file;
@@ -158,7 +158,7 @@ FileChooser::FileChooser(const file::Path& start, const std::string& extension,
             _on_open(_confirmed_file);
     });
     
-    _list->set_font(gui::Font(0.6, gui::Align::Left));
+    _list->set_font(gui::Font(0.6f, gui::Align::Left));
     
     _base.platform()->set_icons({
         "gfx/"+SETTING(app_name).value<std::string>()+"Icon16.png",
@@ -265,7 +265,7 @@ void FileChooser::set_tab(std::string tab) {
 void FileChooser::update_names() {
     _names.clear();
     for(auto &f : _files) {
-        if(f.str() == ".." || !utils::beginsWith(f.filename().to_string(), '.'))
+        if(f.str() == ".." || !utils::beginsWith((std::string)f.filename(), '.'))
             _names.push_back(FileItem(f));
     }
     _list->set_items(_names);
@@ -291,7 +291,7 @@ FileChooser::FileItem::FileItem(const file::Path& path) : _path(path)
 }
 
 FileChooser::FileItem::operator std::string() const {
-    return _path.filename().to_string();
+    return std::string(_path.filename());
 }
 
 Color FileChooser::FileItem::base_color() const {
@@ -369,7 +369,7 @@ void FileChooser::file_selected(size_t, file::Path p) {
             
         } else {
             if(!_selected_text)
-                _selected_text = std::make_shared<StaticText>("Selected: "+_selected_file.str(), Vec2(), Vec2(700, 0), Font(0.6));
+                _selected_text = std::make_shared<StaticText>("Selected: "+_selected_file.str(), Vec2(), Vec2(700, 0), Font(0.6f));
             else
                 _selected_text->set_txt("Selected: "+_selected_file.str());
             
diff --git a/Application/src/commons/common/gui/Graph.cpp b/Application/src/commons/common/gui/Graph.cpp
index 0202220c952c5496aa145a414350862befa78113..39418eef7b4fd9eef4f517ba4725c6db3ea28dad 100644
--- a/Application/src/commons/common/gui/Graph.cpp
+++ b/Application/src/commons/common/gui/Graph.cpp
@@ -630,8 +630,8 @@ void Graph::save_npz(const std::string &filename, std::function<void(float)> *pe
     for (auto &f : _functions)
         results[&f].reserve(_x_range.length()+1);
     
-    int print_step = max(1, int((rx.end - rx.start) * 0.1));
-    for(int x=rx.start; x<=rx.end; x++) {
+    int print_step = max(1, int((rx.end - rx.start) * 0.1f));
+    for(float x=rx.start; x<=rx.end; x++) {
         for (auto &f : _functions) {
             float y0 = f._get_y(x);
             
@@ -645,11 +645,11 @@ void Graph::save_npz(const std::string &filename, std::function<void(float)> *pe
             }
         }
         
-        if (x%print_step == 0 && rx.end - rx.start > 10000 && !quiet) {
+        if (int(x)%print_step == 0 && rx.end - rx.start > 10000 && !quiet) {
             Debug("%d/%.0f done", x, rx.end);
         }
         
-        if(percent_callback && x%100 == 0) {
+        if(percent_callback && int(x)%100 == 0) {
             (*percent_callback)(cmn::abs(x-rx.start) / cmn::abs(rx.end - rx.start));
         }
     }
diff --git a/Application/src/commons/common/gui/Graph.h b/Application/src/commons/common/gui/Graph.h
index f4b7cacedf6592fd25d375c3b97e3e04e89d4259..dc634da9fc16a6e3d136e2ac195f1c4f9cb0331c 100644
--- a/Application/src/commons/common/gui/Graph.h
+++ b/Application/src/commons/common/gui/Graph.h
@@ -57,7 +57,7 @@ namespace gui {
                 _get_y(get_y), _type(type), _name(name), _unit_name(unit_name)
             { }
             
-            float operator()(float x) const {
+            double operator()(double x) const {
                 return _get_y(x);
             }
             
diff --git a/Application/src/commons/common/gui/Section.h b/Application/src/commons/common/gui/Section.h
index 422b5353bcf0f41a289a70ee42a063b9553fbadb..69a117d86c10303120bb47fccf8c293358d30bb6 100644
--- a/Application/src/commons/common/gui/Section.h
+++ b/Application/src/commons/common/gui/Section.h
@@ -136,7 +136,7 @@ namespace gui {
             }
             else {
                 //Debug("Have to insert object of type '%S'", &type);
-                _children.insert(_children.begin() + _index, d);
+                _children.insert(_children.begin() + (int64_t)_index, d);
                 
                 //if(d->type() == Type::VERTICES)
                 //    static_cast<Vertices*>(d)->prepare();
diff --git a/Application/src/commons/common/gui/colors.h b/Application/src/commons/common/gui/colors.h
index ea5aa06bd4f556cfbac6532b801b4b2a6934b235..f81c0335c3ed3787b1d640020b5497f268587f99 100644
--- a/Application/src/commons/common/gui/colors.h
+++ b/Application/src/commons/common/gui/colors.h
@@ -64,13 +64,13 @@ class ColorWheel {
     //int _offset;
     
 public:
-    constexpr ColorWheel(long_t index = 0) : _index(index), _hue(255 + index * (index + 1) * 0.5 * step) {
+    constexpr ColorWheel(long_t index = 0) : _index(index), _hue(int(255 + index * (index + 1) * 0.5 * step)) {
         
     }
     constexpr gui::Color next() {
         //if (_index >= sizeof(colors) / sizeof(gui::Color)) {
         
-        const uint32_t s = _hue % 255;
+        const uint8_t s = _hue % 255;
         //const uint32_t h = s % 100;
         const gui::Color hsv(s, 255, 255);
         //_hue += step;
diff --git a/Application/src/commons/common/gui/types/Basic.h b/Application/src/commons/common/gui/types/Basic.h
index d8336a9c84d1046fd39bf0f7548dcb83a183acd0..4e66d0ef4cc2e8bdea28c793f5f021ea86e8595f 100644
--- a/Application/src/commons/common/gui/types/Basic.h
+++ b/Application/src/commons/common/gui/types/Basic.h
@@ -82,7 +82,7 @@ namespace gui {
         }
         
 #ifdef HAS_IMGUI
-        constexpr Color(const ImColor& c) : Color(c.Value.x, c.Value.y, c.Value.z, c.Value.w) {}
+        constexpr Color(const ImColor& c) : Color(uint8_t(c.Value.x * 255), uint8_t(c.Value.y * 255), uint8_t(c.Value.z * 255), uint8_t(c.Value.w * 255)) {}
         operator ImColor() const { return ImColor(r, g, b, a); }
 #endif
         
@@ -102,10 +102,10 @@ namespace gui {
         }
         
         constexpr Color float_multiply(const Color& other) const {
-            return Color(r * float(other.r) / 255.f,
-                         g * float(other.g) / 255.f,
-                         b * float(other.b) / 255.f,
-                         a * float(other.a) / 255.f);
+            return Color(uint8_t(r * float(other.r) / 255.f),
+                         uint8_t(g * float(other.g) / 255.f),
+                         uint8_t(b * float(other.b) / 255.f),
+                         uint8_t(a * float(other.a) / 255.f));
         }
         
         constexpr uint32_t to_integer() const {
@@ -122,13 +122,13 @@ namespace gui {
         
         constexpr inline Color brighten(float factor) const {
             Color hsv(toHSV());
-            Color rgb(Color(hsv.r, hsv.g, saturate(factor * hsv.b), hsv.a).HSV2RGB());
+            Color rgb(Color(hsv.r, hsv.g, (uint8_t)saturate(factor * hsv.b), hsv.a).HSV2RGB());
             return Color(rgb.r, rgb.g, rgb.b, this->a);
         }
         
         constexpr inline Color brightenHSL(float factor) const {
             Color hsl(toHSL());
-            Color rgb(hsl.blue(saturate(hsl.b * factor)).HSL2RGB());
+            Color rgb(hsl.blue((uint8_t)saturate(hsl.b * factor)).HSL2RGB());
             return Color(rgb.r, rgb.g, rgb.b, this->a);
         }
         
@@ -147,7 +147,7 @@ namespace gui {
         
         constexpr inline Color saturation(float factor) const {
             Color hsv(toHSV());
-            Color rgb(Color(hsv.r, saturate(factor * hsv.g), hsv.b, hsv.a).HSV2RGB());
+            Color rgb(Color(hsv.r, (uint8_t)saturate(factor * hsv.g), hsv.b, hsv.a).HSV2RGB());
             return Color(rgb.r, rgb.g, rgb.b, this->a);
         }
         
@@ -155,7 +155,7 @@ namespace gui {
             float h = r / 255.f, s = g / 255.f, v = b / 255.f;
             float R = 0, G = 0, B = 0;
             
-            int i = const_funcs::floor(h * 6);
+            auto i = (int)const_funcs::floor(h * 6);
             auto f = h * 6 - i;
             auto p = v * (1 - s);
             auto q = v * (1 - f * s);
@@ -170,7 +170,7 @@ namespace gui {
                 case 5: R = v; G = p; B = q; break;
             }
             
-            return Color(R * 255, G * 255, B * 255, 255);
+            return Color(uint8_t(R * 255), uint8_t(G * 255), uint8_t(B * 255), uint8_t(255));
         }
         
         constexpr Color toHSV() const {
@@ -193,7 +193,7 @@ namespace gui {
             ? 0
             : d / Cmax;
             
-            return Color(saturate(H / 360.f * 255), S * 255, Cmax * 255);
+            return Color((uint8_t)saturate(H / 360.f * 255), uint8_t(S * 255), uint8_t(Cmax * 255));
         }
         
         constexpr Color toHSL() const {
@@ -239,7 +239,7 @@ namespace gui {
                     H -= 1;
             }
             
-            return Color(H * 255.f, S * 255.f, L * 255.f);
+            return Color(uint8_t(H * 255.f), uint8_t(S * 255.f), uint8_t(L * 255.f));
         }
         
         constexpr static float Hue_2_RGB( float v1, float v2, float vH )             //Function Hue_2_RGB
@@ -283,7 +283,7 @@ namespace gui {
                 B = 255.f * Hue_2_RGB( var_1, var_2, H - ( 1 / 3.f ) );
             }
             
-            return Color(R, saturate(G), saturate(B));
+            return Color(uint8_t(R), (uint8_t)saturate(G), (uint8_t)saturate(B));
         }
         
         constexpr float diff(const Color& other) const {
@@ -313,31 +313,31 @@ namespace gui {
          Transparent = Color(0, 0, 0, 0);
     
     constexpr inline Color operator*(const Color& c0, const Color& c1) {
-        return Color(saturate((int)c0.r * (int)c1.r),
-                     saturate((int)c0.g * (int)c1.g),
-                     saturate((int)c0.b * (int)c1.b),
-                     saturate((int)c0.a * (int)c1.a));
+        return Color((uint8_t)saturate((int)c0.r * (int)c1.r),
+                     (uint8_t)saturate((int)c0.g * (int)c1.g),
+                     (uint8_t)saturate((int)c0.b * (int)c1.b),
+                     (uint8_t)saturate((int)c0.a * (int)c1.a));
     }
     
     constexpr inline Color operator*(const Color& c0, float scalar) {
-        return Color(saturate((float)c0.r * scalar),
-                     saturate((float)c0.g * scalar),
-                     saturate((float)c0.b * scalar),
-                     saturate((float)c0.a * scalar));
+        return Color((uint8_t)saturate((float)c0.r * scalar),
+                     (uint8_t)saturate((float)c0.g * scalar),
+                     (uint8_t)saturate((float)c0.b * scalar),
+                     (uint8_t)saturate((float)c0.a * scalar));
     }
     
     constexpr inline Color operator-(const Color& c0, const Color& c1) {
-        return Color(saturate((int)c0.r - (int)c1.r),
-                     saturate((int)c0.g - (int)c1.g),
-                     saturate((int)c0.b - (int)c1.b),
-                     saturate((int)c0.a - (int)c1.a));
+        return Color((uint8_t)saturate((int)c0.r - (int)c1.r),
+                     (uint8_t)saturate((int)c0.g - (int)c1.g),
+                     (uint8_t)saturate((int)c0.b - (int)c1.b),
+                     (uint8_t)saturate((int)c0.a - (int)c1.a));
     }
     
     constexpr inline Color operator+(const Color& c0, const Color& c1) {
-        return Color(saturate((int)c0.r + (int)c1.r),
-                     saturate((int)c0.g + (int)c1.g),
-                     saturate((int)c0.b + (int)c1.b),
-                     saturate((int)c0.a + (int)c1.a));
+        return Color((uint8_t)saturate((int)c0.r + (int)c1.r),
+                     (uint8_t)saturate((int)c0.g + (int)c1.g),
+                     (uint8_t)saturate((int)c0.b + (int)c1.b),
+                     (uint8_t)saturate((int)c0.a + (int)c1.a));
     }
 
     class Vertex {
diff --git a/Application/src/commons/common/gui/types/Histogram.h b/Application/src/commons/common/gui/types/Histogram.h
index 701f05917ef787b939f6f156fb46875e0012507f..d72b79cc42eceb1846946427bfa2f1e3278ab189 100644
--- a/Application/src/commons/common/gui/types/Histogram.h
+++ b/Application/src/commons/common/gui/types/Histogram.h
@@ -42,7 +42,7 @@ namespace gui {
         float padding;
         float _y_label_width;
         //std::vector<float> _sum_bin;
-        float _max_samples;
+        size_t _max_samples;
         Vec2 element;
         frange yticks;
         Text _title_obj;
diff --git a/Application/src/commons/common/misc/Grid.cpp b/Application/src/commons/common/misc/Grid.cpp
index 12e76186bf76c823250bad93cf463245a628e6cd..274c5372775484fb90f21a29fb2b95cd26275825 100644
--- a/Application/src/commons/common/misc/Grid.cpp
+++ b/Application/src/commons/common/misc/Grid.cpp
@@ -1,4 +1,5 @@
 #include "Grid.h"
+#include <misc/metastring.h>
 
 namespace cmn {
 namespace grid {
@@ -10,7 +11,7 @@ PixelGrid::PixelGrid(uint n, const Size2& resolution, const cv::Mat& bg)
 
 uint8_t PixelGrid::query(float x, float y) const {
     auto v = Grid2D<uint8_t>::query(x, y);
-    return v ? v : (x > 0 && y > 0 && x < background.cols && y < background.rows ? background.at<uchar>(y, x) : 0);
+    return v ? v : (x > 0 && y > 0 && x < background.cols && y < background.rows ? background.at<uchar>(narrow_cast<uint8_t>(y), narrow_cast<uint8_t>(x)) : uint8_t(0));
 }
 
 }
diff --git a/Application/src/commons/common/misc/Grid.h b/Application/src/commons/common/misc/Grid.h
index 9feae73a4943b3d9b09c767b0ad64e83bcd89dc5..ef346c310cc324efc722219f40a84badf7982d93 100644
--- a/Application/src/commons/common/misc/Grid.h
+++ b/Application/src/commons/common/misc/Grid.h
@@ -78,8 +78,8 @@ namespace grid {
         
         const decltype(grid)& get_grid() const { return grid; }
         
-        size_t idx(float x, float y) const {
-            return max(0, floorf(min(_resolution.width-1,x) / _scale.x)) + max(0, floorf(min(_resolution.height-1, y) / _scale.y)) * _n;
+        int64_t idx(float x, float y) const {
+            return int64_t(max(0, floorf(min(_resolution.width-1,x) / _scale.x)) + max(0, floorf(min(_resolution.height-1, y) / _scale.y)) * _n);
         }
         
         std::tuple<size_t, size_t> point2grid(float x, float y) const {
@@ -114,9 +114,9 @@ namespace grid {
         }
         
         virtual T query(float x, float y) const {
-            size_t idx = this->idx(x, y);
+            auto idx = this->idx(x, y);
             
-            assert(idx < grid.size());
+            assert((size_t)idx < grid.size());
             auto cell = grid.begin() + idx;
             auto it = find(cell, pixel<T>(x, y));
             if(it == cell->end())
@@ -138,8 +138,8 @@ namespace grid {
             auto cell = grid.begin() + (long)(gx + gy * _n);
             pixel<T> px(x0, y);
             auto it = find(cell, px);
-            size_t i=0;
-            const size_t L = x1 - x0;
+            float i=0;
+            const auto L = x1 - x0;
             
             for(; i<=L && i + x0 < _resolution.width;){
                 if(it == cell->end() || it->y != y) {
@@ -159,16 +159,16 @@ namespace grid {
                 }
                 
                 if(it == cell->end() || it->y != y)
-                    data[i] = T();
+                    data[size_t(i)] = T();
                 else if(it->x != x0 + i) {
                     ++it;
                     assert(it->x > x0 + i);
-                    std::fill(data + i, data + (size_t)min(it->x - x0 + 1, L + 1), T());
+                    std::fill(data + size_t(i), data + (size_t)cmn::min(it->x - x0 + 1, L + 1), T());
                     i = it->x - x0;
                     continue;
                 }
                 else {
-                    data[i] = it->v;
+                    data[size_t(i)] = it->v;
                     ++it;
                 }
                 
diff --git a/Application/src/commons/common/misc/PixelTree.h b/Application/src/commons/common/misc/PixelTree.h
index d60d998314e1a6767b352b7e3c3b05e43f2e47fb..7e2a5bfdb6f9a1797ea74b3cfa5bf9dc40d35336 100644
--- a/Application/src/commons/common/misc/PixelTree.h
+++ b/Application/src/commons/common/misc/PixelTree.h
@@ -101,7 +101,7 @@ namespace pixel {
         }
         
         constexpr static int64_t leaf_index(int64_t x, int32_t y) {
-            return ( ( (int64_t(x) << 32) & 0xFFFFFFFF00000000 ) | int32_t(y) );
+            return int64_t( ( (int64_t(x) << 32) & 0xFFFFFFFF00000000 ) | int64_t(y) );
         }
     };
     
diff --git a/Application/src/commons/common/misc/ThreadPool.h b/Application/src/commons/common/misc/ThreadPool.h
index 4637bf512efac9665e3d76393ae7037be9c0c182..ebef5ee3dabb0027e17c5a116a3fdb0383112a83 100644
--- a/Application/src/commons/common/misc/ThreadPool.h
+++ b/Application/src/commons/common/misc/ThreadPool.h
@@ -93,14 +93,14 @@ namespace cmn {
 
 template<typename F, typename Iterator, typename Pool>
 void distribute_vector(F&& fn, Pool& pool, Iterator start, Iterator end, const uint8_t per_thread_items = 5) {
-    static const uint8_t threads = cmn::hardware_concurrency();
-    size_t i = 0, N = std::distance(start, end);
-    const size_t per_thread = max(1u, N / threads);
+    static const auto threads = cmn::hardware_concurrency();
+    int64_t i = 0, N = std::distance(start, end);
+    const int64_t per_thread = max(1, N / threads);
     
     Iterator nex = start;
     
     for(auto it = start; it != end;) {
-        size_t step = i + per_thread < N ? per_thread : (N - i);
+        auto step = i + per_thread < N ? per_thread : (N - i);
         std::advance(nex, step);
         
         assert(step > 0);
diff --git a/Application/src/commons/common/misc/defines.h b/Application/src/commons/common/misc/defines.h
index 5d088631c9289ad67e5d85a063eff388d94c029e..03f4f17dbae2ba84d68655b06b1be4261d22e931 100644
--- a/Application/src/commons/common/misc/defines.h
+++ b/Application/src/commons/common/misc/defines.h
@@ -1,5 +1,14 @@
 #pragma once
 
+#pragma warning(push, 0)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wall"
+#pragma clang diagnostic ignored "-Wextra"
+#pragma clang diagnostic ignored "-Wsign-conversion"
+#pragma clang diagnostic ignored "-Wimplicit-int-conversion"
+#pragma clang diagnostic ignored "-Wimplicit-float-conversion"
+#pragma clang diagnostic ignored "-Wfloat-conversion"
+
 #include <commons/common/commons.pc.h>
 
 #ifdef _MSC_VER
@@ -18,6 +27,9 @@
     #endif
 #endif
 
+#pragma clang diagnostic pop
+#pragma warning(pop)
+
 #include <misc/MetaObject.h>
 #include <misc/EnumClass.h>
 
@@ -127,6 +139,15 @@ namespace cv {
 #endif
 
 namespace cmn {
+
+template< class T >
+struct remove_cvref {
+    typedef std::remove_cv_t<std::remove_reference_t<T>> type;
+};
+
+template< class T >
+using remove_cvref_t = typename remove_cvref<T>::type;
+
 #if __has_cpp_attribute(deprecated)
 #define DEPRECATED [[deprecated]]
 #else
@@ -175,18 +196,22 @@ namespace cmn {
         return std::isnan(x.x) || std::isnan(x.y);
     }
 
-    template<typename T0, typename T1>
-    constexpr inline auto min(const T0& x, const T1& y,
-                              typename std::enable_if<(!(std::is_unsigned<T0>::value ^ std::is_unsigned<T1>::value)
-                                                       && std::is_integral<T0>::value) // allow only same-signedness
-                              || std::is_floating_point<T0>::value, bool>::type * = NULL)
-    -> decltype(x+y)
+    template<typename T0, typename T1,
+        typename T0_ = typename remove_cvref<T0>::type,
+        typename T1_ = typename remove_cvref<T1>::type,
+        typename Result = typename std::conditional<(sizeof(T0_) > sizeof(T1_)), T0_, T1_>::type >
+    constexpr inline auto min(T0&& x, T1&& y)
+        -> typename std::enable_if< std::is_signed<T0_>::value == std::is_signed<T1_>::value
+                                && (std::is_integral<T0_>::value || std::is_floating_point<T0_>::value)
+                                && (std::is_integral<T1_>::value || std::is_floating_point<T1_>::value), Result>::type
     {
-        return std::min(decltype(x+y)(x), decltype(x+y)(y));
+        return std::min(Result(x), Result(y));
     }
     
     template<typename T0, typename T1>
-    constexpr inline T0 min(const T0& x, const T1& y, typename std::enable_if<std::is_same<decltype(x.x), decltype(x.y)>::value, bool>::type * =NULL) {
+    constexpr inline auto min(const T0& x, const T1& y)
+        -> typename std::enable_if<std::is_same<decltype(x.x), decltype(x.y)>::value, T0>::type
+    {
         return T0(std::min(decltype(x.x+y.x)(x.x), decltype(x.x+y.x)(y.x)),
                   std::min(decltype(x.y+y.y)(x.y), decltype(x.y+y.y)(y.y)));
     }
@@ -201,19 +226,23 @@ namespace cmn {
     constexpr inline auto min(const T0& x, const T1& y, const T2& z) -> decltype(x+y+z) {
         return std::min(decltype(x+y+z)(x), std::min(decltype(x+y+z)(y), decltype(x+y+z)(z)));
     }
-    
-    template<typename T0, typename T1>
-    constexpr inline auto max(const T0& x, const T1& y,
-                              typename std::enable_if<(!(std::is_unsigned<T0>::value ^ std::is_unsigned<T1>::value)
-                                                       && std::is_integral<T0>::value) // allow only same-signedness
-                              || std::is_floating_point<T0>::value, bool>::type * = NULL)
-    -> decltype(x+y)
+        
+    template<typename T0, typename T1,
+        typename T0_ = typename remove_cvref<T0>::type,
+        typename T1_ = typename remove_cvref<T1>::type,
+        typename Result = typename std::conditional<(sizeof(T0_) > sizeof(T1_)), T0_, T1_>::type >
+    constexpr inline auto max(T0&& x, T1&& y)
+        -> typename std::enable_if< std::is_signed<T0_>::value == std::is_signed<T1_>::value
+                                && (std::is_integral<T0_>::value || std::is_floating_point<T0_>::value)
+                                && (std::is_integral<T1_>::value || std::is_floating_point<T1_>::value), Result>::type
     {
-        return std::max(decltype(x+y)(x), decltype(x+y)(y));
+        return std::max(Result(x), Result(y));
     }
     
     template<typename T0, typename T1>
-    constexpr inline T0 max(const T0& x, const T1& y, typename std::enable_if<std::is_same<decltype(x.x), decltype(x.y)>::value, bool>::type * =NULL) {
+    constexpr inline auto max(const T0& x, const T1& y)
+        -> typename std::enable_if<std::is_same<decltype(x.x), decltype(x.y)>::value, T0>::type
+    {
         return T0(std::max(decltype(x.x+y.x)(x.x), decltype(x.x+y.x)(y.x)),
                   std::max(decltype(x.y+y.y)(x.y), decltype(x.y+y.y)(y.y)));
     }
@@ -313,7 +342,7 @@ namespace cmn {
     typename T::value_type percentile(const T& values, float percent, typename std::enable_if<is_set<T>::value || is_container<T>::value, T>::type* = NULL)
     {
         using C = typename std::conditional<std::is_floating_point<typename T::value_type>::value,
-            typename T::value_type, float>::type;
+            typename T::value_type, double>::type;
         
         auto start = values.begin();
         
@@ -321,7 +350,7 @@ namespace cmn {
             return std::numeric_limits<typename T::value_type>::max();
         
         C stride = C(values.size()-1) * percent;
-        std::advance(start, stride);
+        std::advance(start, (int64_t)stride);
         C A = *start;
         
         auto second = start;
diff --git a/Application/src/commons/common/misc/detail.h b/Application/src/commons/common/misc/detail.h
index 902e0b5197af17740db2d9c101d7cc90640bb6bf..26a618b8e3a8dfd510e10d2799ab7da1e75ca525 100644
--- a/Application/src/commons/common/misc/detail.h
+++ b/Application/src/commons/common/misc/detail.h
@@ -102,7 +102,7 @@ namespace cmn {
         
     private:
         constexpr size_t num_steps() const {
-            return ((last - first) / step + T(1));
+            return size_t((last - first) / step + T(1));
         }
         
     public:
@@ -150,7 +150,7 @@ namespace cmn {
             bool operator!=(const _iterator& rhs) const { return value != rhs.value; }
 
             reference operator*() {
-                return value_type(ptr_->first + value_type(value * ptr_->step));
+                return value_type(ptr_->first + value_type(value) * value_type(ptr_->step));
             }
             pointer operator->() {
                 return *ptr_;
@@ -787,7 +787,7 @@ namespace cmn {
     //! Escapes html reserved characters in a string
     inline std::string escape_html(const std::string& data) {
         std::string buffer;
-        buffer.reserve(data.size()*1.1f);
+        buffer.reserve(size_t(data.size()*1.1f));
         for(size_t pos = 0; pos != data.size(); ++pos) {
             switch(data[pos]) {
                 case '&':  buffer.append("&amp;");       break;
@@ -842,7 +842,7 @@ namespace cmn {
                                 const std::function<void(std::shared_ptr<K>, std::shared_ptr<V>)>& prepare = nullptr)
     {
         // Delete elements from the end of vector if its too long
-        for(size_t i=vector.size()-1; !vector.empty() && i>=compare.size(); i--) {
+        for(int64_t i=int64_t(vector.size())-1; !vector.empty() && i>=(int64_t)compare.size(); i--) {
             vector.erase(vector.begin() + i);
         }
         
@@ -864,11 +864,11 @@ namespace cmn {
         }
     }
     
-    inline uint32_t hardware_concurrency() {
+    inline uint8_t hardware_concurrency() {
 #if TRACKER_GLOBAL_THREADS
         return TRACKER_GLOBAL_THREADS;
 #else
-        uint32_t c = std::thread::hardware_concurrency();
+        auto c = (uint8_t)saturate(std::thread::hardware_concurrency());
         if(!c)
             return 1;
         return c;
diff --git a/Application/src/commons/common/misc/metastring.h b/Application/src/commons/common/misc/metastring.h
index e8c7784577707bca03cd5a026f1ad2b65b32ff4a..40f57d0f3ce07cb8009e5b8bc5bed3e14866b2d3 100644
--- a/Application/src/commons/common/misc/metastring.h
+++ b/Application/src/commons/common/misc/metastring.h
@@ -37,7 +37,7 @@ namespace cmn {
         uint64_t timestamp;
         
         std::string to_string() const {
-            static constexpr std::array<cmn::string_view, 5> names{{"us", "ms", "s", "min", "h"}};
+            static constexpr std::array<std::string_view, 5> names{{"us", "ms", "s", "min", "h"}};
             static constexpr std::array<double, 5> ratios{{1000, 1000, 60, 60, 24}};
             
             double scaled = timestamp, previous_scaled = 0;
@@ -62,7 +62,7 @@ namespace cmn {
         }
         
         std::string to_html() const {
-            static constexpr std::array<cmn::string_view, 5> names{{"us", "ms", "s", "min", "h"}};
+            static constexpr std::array<std::string_view, 5> names{{"us", "ms", "s", "min", "h"}};
             static constexpr std::array<double, 5> ratios{{1000, 1000, 60, 60, 24}};
             
             double scaled = timestamp, previous_scaled = 0;
@@ -628,7 +628,7 @@ namespace cmn {
         {
             if(!str.empty() && str[0] == '\'' && str.back() == '\'')
                 return Q(std::stod(str.substr(1,str.length()-2)));
-            return std::stod(str);
+            return (Q)std::stod(str);
         }
         
         template<class T, class Q = typename std::remove_cv<T>::type>
@@ -877,8 +877,8 @@ namespace cmn {
                 throw CustomException<std::invalid_argument>("Illegal Rangef format.");
             }
             
-            float x = Meta::fromStr<double>(parts[0]);
-            float y = Meta::fromStr<double>(parts[1]);
+            auto x = Meta::fromStr<double>(parts[0]);
+            auto y = Meta::fromStr<double>(parts[1]);
             
             return Range<double>(x, y);
         }
@@ -891,8 +891,8 @@ namespace cmn {
                 throw CustomException<std::invalid_argument>("Illegal Rangef format.");
             }
             
-            float x = Meta::fromStr<float>(parts[0]);
-            float y = Meta::fromStr<float>(parts[1]);
+            auto x = Meta::fromStr<float>(parts[0]);
+            auto y = Meta::fromStr<float>(parts[1]);
             
             return Rangef(x, y);
         }
@@ -905,10 +905,10 @@ namespace cmn {
                 throw CustomException<std::invalid_argument>("Illegal Rangel format.");
             }
             
-            long_t x = Meta::fromStr<long_t>(parts[0]);
-            long_t y = Meta::fromStr<long_t>(parts[1]);
+            auto x = Meta::fromStr<long_t>(parts[0]);
+            auto y = Meta::fromStr<long_t>(parts[1]);
             
-            return Rangel(x, y);
+            return Range(x, y);
         }
         
         template<class Q>
@@ -1056,6 +1056,50 @@ typename std::conditional<
 	double
 >::type;
 
+template<typename To, typename From>
+void fail_type(From&& value) {
+    using FromType = typename remove_cvref<From>::type;
+    using ToType = typename remove_cvref<To>::type;
+    
+    auto type1 = Meta::name<FromType>();
+    auto type2 = Meta::name<ToType>();
+    
+    auto value1 = Meta::toStr(value);
+    
+    auto start1 = Meta::toStr(std::numeric_limits<FromType>::min());
+    auto end1 = Meta::toStr(std::numeric_limits<FromType>::max());
+    
+    auto start2 = Meta::toStr(std::numeric_limits<ToType>::min());
+    auto end2 = Meta::toStr(std::numeric_limits<ToType>::max());
+    
+    Warning("Failed converting %S(%S) [%S,%S] -> type %S [%S,%S]", &type1, &value1, &start1, &end1, &type2, &start2, &end2);
+}
+
+template<typename To, typename From>
+constexpr To sign_cast(From&& value) {
+    using FromType = typename remove_cvref<From>::type;
+    using ToType = typename remove_cvref<To>::type;
+    
+    if constexpr(!std::is_floating_point<ToType>::value
+                 && std::is_integral<ToType>::value)
+    {
+        if constexpr(std::is_signed<ToType>::value) {
+            if constexpr(value > std::numeric_limits<ToType>::max())
+                fail_type<To, From>(std::forward<FromType>(value));
+            
+        } else if constexpr(std::is_signed<FromType>::value) {
+            if (value < 0)
+                fail_type<To, From>(std::forward<From>(value));
+            
+            using bigger_type = typename std::conditional<(sizeof(FromType) > sizeof(ToType)), FromType, ToType>::type;
+            if (bigger_type(value) > bigger_type(std::numeric_limits<ToType>::max()))
+                fail_type<To, From>(std::forward<From>(value));
+        }
+    }
+    
+    return static_cast<To>(std::forward<From>(value));
+}
+
 template<typename To, typename From>
 constexpr bool check_narrow_cast(const From& value) {
     using FromType = typename remove_cvref<From>::type;
@@ -1157,4 +1201,4 @@ template<typename To, typename From>
 constexpr To narrow_cast(From&& value) {
     return narrow_cast<To, From>(std::forward<From>(value), tag::warn_on_error{});
 }
-}
\ No newline at end of file
+}
diff --git a/Application/src/commons/common/misc/string_view.cpp b/Application/src/commons/common/misc/string_view.cpp
deleted file mode 100644
index c674c6f09c5d089dedca4ba85ddee0405202f37c..0000000000000000000000000000000000000000
--- a/Application/src/commons/common/misc/string_view.cpp
+++ /dev/null
@@ -1,4 +0,0 @@
-#include "string_view.h"
-
-namespace cmn {
-}
diff --git a/Application/src/commons/common/misc/string_view.h b/Application/src/commons/common/misc/string_view.h
deleted file mode 100644
index 9328af57cd0dd7afdca6d57469148edb60c06b8a..0000000000000000000000000000000000000000
--- a/Application/src/commons/common/misc/string_view.h
+++ /dev/null
@@ -1,655 +0,0 @@
-/*
- � Copyright (c) Marshall Clow 2012-2015.
- � Copyright Beman Dawes 2015
- 
- Distributed under the Boost Software License, Version 1.0. (See accompanying
- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
- 
- For more information, see http://www.boost.org
- 
- Based on the StringRef implementation in LLVM (http://llvm.org) and
- N3422 by Jeffrey Yasskin
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3442.html
- Updated July 2015 to reflect the Library Fundamentals TS
- http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4480.html
- */
-
-#ifndef BOOST_STRING_VIEW_HPP
-#define BOOST_STRING_VIEW_HPP
-
-#include <cstddef>
-#include <stdexcept>
-#include <algorithm>
-#include <iterator>
-#include <string>
-#include <cstring>
-#include <iosfwd>
-#include <commons/common/cpputils/cpputils.h>
-
-namespace cmn {
-    
-    namespace detail {
-        //  A helper functor because sometimes we don't have lambdas
-        template <typename charT, typename traits>
-        class string_view_traits_eq {
-        public:
-            string_view_traits_eq ( charT ch ) : ch_(ch) {}
-            bool operator()( charT val ) const { return traits::eq (ch_, val); }
-            charT ch_;
-        };
-    }
-    
-    template<typename charT, typename traits = std::char_traits<charT>>  // traits defaulted in string_view_fwd.hpp
-    class basic_string_view {
-    public:
-        // types
-        typedef traits                                traits_type;
-        typedef charT                                 value_type;
-        typedef charT*                                pointer;
-        typedef const charT*                          const_pointer;
-        typedef charT&                                reference;
-        typedef const charT&                          const_reference;
-        typedef const_pointer                         const_iterator; // impl-defined
-        typedef const_iterator                        iterator;
-        typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
-        typedef const_reverse_iterator                reverse_iterator;
-        typedef std::size_t                           size_type;
-        typedef std::ptrdiff_t                        difference_type;
-        static const size_type     npos = size_type(-1);
-        
-        // construct/copy
-        constexpr basic_string_view() noexcept
-        : ptr_(NULL), len_(0) {}
-        
-        // by defaulting these functions, basic_string_ref becomes
-        //  trivially copy/move constructible.
-        constexpr basic_string_view(const basic_string_view &rhs) noexcept = default;
-        basic_string_view& operator=(const basic_string_view &rhs) noexcept = default;
-        
-        template<typename Allocator>
-        basic_string_view(const std::basic_string<charT, traits,
-                          Allocator>& str) noexcept
-        : ptr_(str.data()), len_(str.length()) {}
-        
-        constexpr basic_string_view(const charT* str)
-        : ptr_(str), len_(traits::length(str)) {}
-        
-        constexpr basic_string_view(const charT* str, size_type len)
-        : ptr_(str), len_(len) {}
-        
-        // iterators
-        constexpr const_iterator   begin() const noexcept { return ptr_; }
-        constexpr const_iterator  cbegin() const noexcept { return ptr_; }
-        constexpr const_iterator     end() const noexcept { return ptr_ + len_; }
-        constexpr const_iterator    cend() const noexcept { return ptr_ + len_; }
-        const_reverse_iterator  rbegin() const noexcept { return const_reverse_iterator(end()); }
-        const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(end()); }
-        const_reverse_iterator    rend() const noexcept { return const_reverse_iterator(begin()); }
-        const_reverse_iterator   crend() const noexcept { return const_reverse_iterator(begin()); }
-        
-        // capacity
-        constexpr size_type size()     const noexcept { return len_; }
-        constexpr size_type length()   const noexcept { return len_; }
-        constexpr size_type max_size() const noexcept { return len_; }
-        constexpr bool empty()         const noexcept { return len_ == 0; }
-        
-        // element access
-        constexpr const_reference operator[](size_type pos) const noexcept { return ptr_[pos]; }
-        
-        constexpr const_reference at(size_t pos) const {
-            return pos >= len_ ? std::out_of_range("boost::string_view::at") : ptr_[pos];
-            //             if ( pos >= len_ )
-            //                 U_EXCEPTION( std::out_of_range ( "boost::string_view::at" ) );
-            //             return ptr_[pos];
-        }
-        
-        constexpr const_reference front() const                { return ptr_[0]; }
-        constexpr const_reference back()  const                { return ptr_[len_-1]; }
-        constexpr const_pointer data()    const noexcept { return ptr_; }
-        
-        // modifiers
-        void clear() noexcept { len_ = 0; }          // Boost extension
-        
-         void remove_prefix(size_type n) {
-            if ( n > len_ )
-                n = len_;
-            ptr_ += n;
-            len_ -= n;
-        }
-        
-         void remove_suffix(size_type n) {
-            if ( n > len_ )
-                n = len_;
-            len_ -= n;
-        }
-        
-         void swap(basic_string_view& s) noexcept {
-            std::swap(ptr_, s.ptr_);
-            std::swap(len_, s.len_);
-        }
-        
-        // basic_string_view string operations
-        template<typename Allocator>
-        explicit operator std::basic_string<charT, traits, Allocator>() const {
-            return std::basic_string<charT, traits, Allocator>(begin(), end());
-        }
-        
-        template<typename Allocator = std::allocator<charT> >
-        std::basic_string<charT, traits, Allocator> to_string(const Allocator& a = Allocator()) const {
-            return std::basic_string<charT, traits, Allocator>(begin(), end(), a);
-        }
-        
-        size_type copy(charT* s, size_type n, size_type pos=0) const {
-            if (pos > size())
-                U_EXCEPTION(std::out_of_range("string_view::copy" ).what());
-            size_type rlen = (std::min)(n, len_ - pos);
-            // use std::copy(begin() + pos, begin() + pos + rlen, s) rather than
-            // std::copy_n(begin() + pos, rlen, s) to support pre-C++11 standard libraries
-            std::copy(begin() + pos, begin() + pos + rlen, s);
-            return rlen;
-        }
-        
-        constexpr basic_string_view substr(size_type pos, size_type n=npos) const {
-            if ( pos > size())
-                U_EXCEPTION( std::out_of_range ( "string_view::substr" ).what() );
-            if (n == npos || pos + n > size())
-                n = size () - pos;
-            return basic_string_view(data() + pos, n);
-        }
-        
-        constexpr int compare(basic_string_view x) const noexcept {
-            const int cmp = traits::compare(ptr_, x.ptr_, (std::min)(len_, x.len_));
-            return cmp != 0 ? cmp : (len_ == x.len_ ? 0 : len_ < x.len_ ? -1 : 1);
-        }
-        
-        constexpr int compare(size_type pos1, size_type n1, basic_string_view x)
-        const noexcept {
-            return substr(pos1, n1).compare(x);
-        }
-        
-        constexpr int compare(size_type pos1, size_type n1,
-                                          basic_string_view x, size_type pos2, size_type n2) const {
-            return substr(pos1, n1).compare(x.substr(pos2, n2));
-        }
-        
-        constexpr int compare(const charT* x) const {
-            return compare(basic_string_view(x));
-        }
-        
-        constexpr int compare(size_type pos1, size_type n1, const charT* x) const {
-            return substr(pos1, n1).compare(basic_string_view(x));
-        }
-        
-        constexpr int compare(size_type pos1, size_type n1,
-                                          const charT* x, size_type n2) const {
-            return substr(pos1, n1).compare(basic_string_view(x, n2));
-        }
-        
-        //  Searches
-        constexpr bool starts_with(charT c) const noexcept {              // Boost extension
-            return !empty() && traits::eq(c, front());
-        }
-        
-        constexpr bool starts_with(basic_string_view x) const noexcept {  // Boost extension
-            return len_ >= x.len_ && traits::compare(ptr_, x.ptr_, x.len_) == 0;
-        }
-        
-        constexpr bool ends_with(charT c) const noexcept {                // Boost extension
-            return !empty() && traits::eq(c, back());
-        }
-        
-        constexpr bool ends_with(basic_string_view x) const noexcept {    // Boost extension
-            return len_ >= x.len_ &&
-            traits::compare(ptr_ + len_ - x.len_, x.ptr_, x.len_) == 0;
-        }
-        
-        //  find
-        constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept {
-            if (pos > size())
-                return npos;
-            if (s.empty())
-                return pos;
-            const_iterator iter = std::search(this->cbegin() + pos, this->cend(),
-                                              s.cbegin (), s.cend (), traits::eq);
-            return iter == this->cend () ? npos : std::distance(this->cbegin (), iter);
-        }
-        constexpr size_type find(charT c, size_type pos = 0) const noexcept
-        { return find(basic_string_view(&c, 1), pos); }
-        constexpr size_type find(const charT* s, size_type pos, size_type n) const noexcept
-        { return find(basic_string_view(s, n), pos); }
-        constexpr size_type find(const charT* s, size_type pos = 0) const noexcept
-        { return find(basic_string_view(s), pos); }
-        
-        //  rfind
-         size_type rfind(basic_string_view s, size_type pos = npos) const noexcept {
-            if (len_ < s.len_)
-                return npos;
-            if (pos > len_ - s.len_)
-                pos = len_ - s.len_;
-            if (s.len_ == 0u)     // an empty string is always found
-                return pos;
-            for (const charT* cur = ptr_ + pos; ; --cur) {
-                if (traits::compare(cur, s.ptr_, s.len_) == 0)
-                    return cur - ptr_;
-                if (cur == ptr_)
-                    return npos;
-            };
-        }
-        constexpr size_type rfind(charT c, size_type pos = npos) const noexcept
-        { return rfind(basic_string_view(&c, 1), pos); }
-        constexpr size_type rfind(const charT* s, size_type pos, size_type n) const noexcept
-        { return rfind(basic_string_view(s, n), pos); }
-        constexpr size_type rfind(const charT* s, size_type pos = npos) const noexcept
-        { return rfind(basic_string_view(s), pos); }
-        
-        //  find_first_of
-        constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept {
-            if (pos >= len_ || s.len_ == 0)
-                return npos;
-            const_iterator iter = std::find_first_of
-            (this->cbegin () + pos, this->cend (), s.cbegin (), s.cend (), traits::eq);
-            return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
-        }
-        constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept
-        { return find_first_of(basic_string_view(&c, 1), pos); }
-        constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const noexcept
-        { return find_first_of(basic_string_view(s, n), pos); }
-        constexpr size_type find_first_of(const charT* s, size_type pos = 0) const noexcept
-        { return find_first_of(basic_string_view(s), pos); }
-        
-        //  find_last_of
-        constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept {
-            if (s.len_ == 0u)
-                return npos;
-            if (pos >= len_)
-                pos = 0;
-            else
-                pos = len_ - (pos+1);
-            const_reverse_iterator iter = std::find_first_of
-            ( this->crbegin () + pos, this->crend (), s.cbegin (), s.cend (), traits::eq );
-            return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter);
-        }
-        constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept
-        { return find_last_of(basic_string_view(&c, 1), pos); }
-        constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const noexcept
-        { return find_last_of(basic_string_view(s, n), pos); }
-        constexpr size_type find_last_of(const charT* s, size_type pos = npos) const noexcept
-        { return find_last_of(basic_string_view(s), pos); }
-        
-        //  find_first_not_of
-        constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept {
-            if (pos >= len_)
-                return npos;
-            if (s.len_ == 0)
-                return pos;
-            const_iterator iter = find_not_of ( this->cbegin () + pos, this->cend (), s );
-            return iter == this->cend () ? npos : std::distance ( this->cbegin (), iter );
-        }
-        constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept
-        { return find_first_not_of(basic_string_view(&c, 1), pos); }
-        constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const noexcept
-        { return find_first_not_of(basic_string_view(s, n), pos); }
-        constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const noexcept
-        { return find_first_not_of(basic_string_view(s), pos); }
-        
-        //  find_last_not_of
-        constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept {
-            if (pos >= len_)
-                pos = len_ - 1;
-            if (s.len_ == 0u)
-                return pos;
-            pos = len_ - (pos+1);
-            const_reverse_iterator iter = find_not_of ( this->crbegin () + pos, this->crend (), s );
-            return iter == this->crend () ? npos : reverse_distance ( this->crbegin (), iter );
-        }
-        constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept
-        { return find_last_not_of(basic_string_view(&c, 1), pos); }
-        constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const noexcept
-        { return find_last_not_of(basic_string_view(s, n), pos); }
-        constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const noexcept
-        { return find_last_not_of(basic_string_view(s), pos); }
-        
-    private:
-        template <typename r_iter>
-        size_type reverse_distance(r_iter first, r_iter last) const noexcept {
-            // Portability note here: std::distance is not NOEXCEPT, but calling it with a string_view::reverse_iterator will not throw.
-            return len_ - 1 - std::distance ( first, last );
-        }
-        
-        template <typename Iterator>
-        Iterator find_not_of(Iterator first, Iterator last, basic_string_view s) const noexcept {
-            for (; first != last ; ++first)
-                if ( 0 == traits::find(s.ptr_, s.len_, *first))
-                    return first;
-            return last;
-        }
-        
-        const charT *ptr_;
-        std::size_t len_;
-    };
-    
-    typedef basic_string_view<char,     std::char_traits<char> >        string_view;
-    
-    //  Comparison operators
-    //  Equality
-    template<typename charT, typename traits>
-    inline bool operator==(basic_string_view<charT, traits> x,
-                           basic_string_view<charT, traits> y) noexcept {
-    if (x.size () != y.size ()) return false;
-    return x.compare(y) == 0;
-}
-
-//  Inequality
-template<typename charT, typename traits>
-inline bool operator!=(basic_string_view<charT, traits> x,
-                       basic_string_view<charT, traits> y) noexcept {
-if ( x.size () != y.size ()) return true;
-return x.compare(y) != 0;
-}
-
-//  Less than
-template<typename charT, typename traits>
-inline bool operator<(basic_string_view<charT, traits> x,
-                      basic_string_view<charT, traits> y) noexcept {
-return x.compare(y) < 0;
-}
-
-//  Greater than
-template<typename charT, typename traits>
-inline bool operator>(basic_string_view<charT, traits> x,
-                      basic_string_view<charT, traits> y) noexcept {
-return x.compare(y) > 0;
-}
-
-//  Less than or equal to
-template<typename charT, typename traits>
-inline bool operator<=(basic_string_view<charT, traits> x,
-                       basic_string_view<charT, traits> y) noexcept {
-return x.compare(y) <= 0;
-}
-
-//  Greater than or equal to
-template<typename charT, typename traits>
-inline bool operator>=(basic_string_view<charT, traits> x,
-                       basic_string_view<charT, traits> y) noexcept {
-return x.compare(y) >= 0;
-}
-
-// "sufficient additional overloads of comparison functions"
-template<typename charT, typename traits, typename Allocator>
-inline bool operator==(basic_string_view<charT, traits> x,
-                       const std::basic_string<charT, traits, Allocator> & y) noexcept {
-return x == basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator==(const std::basic_string<charT, traits, Allocator> & x,
-                       basic_string_view<charT, traits> y) noexcept {
-return basic_string_view<charT, traits>(x) == y;
-}
-
-template<typename charT, typename traits>
-inline bool operator==(basic_string_view<charT, traits> x,
-                       const charT * y) noexcept {
-return x == basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator==(const charT * x,
-                       basic_string_view<charT, traits> y) noexcept {
-return basic_string_view<charT, traits>(x) == y;
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator!=(basic_string_view<charT, traits> x,
-                       const std::basic_string<charT, traits, Allocator> & y) noexcept {
-return x != basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator!=(const std::basic_string<charT, traits, Allocator> & x,
-                       basic_string_view<charT, traits> y) noexcept {
-return basic_string_view<charT, traits>(x) != y;
-}
-
-template<typename charT, typename traits>
-inline bool operator!=(basic_string_view<charT, traits> x,
-                       const charT * y) noexcept {
-return x != basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator!=(const charT * x,
-                       basic_string_view<charT, traits> y) noexcept {
-return basic_string_view<charT, traits>(x) != y;
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator<(basic_string_view<charT, traits> x,
-                      const std::basic_string<charT, traits, Allocator> & y) noexcept {
-return x < basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator<(const std::basic_string<charT, traits, Allocator> & x,
-                      basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) < y;
-}
-
-template<typename charT, typename traits>
-inline bool operator<(basic_string_view<charT, traits> x,
-                      const charT * y) noexcept {
-    return x < basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator<(const charT * x,
-                      basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) < y;
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator>(basic_string_view<charT, traits> x,
-                      const std::basic_string<charT, traits, Allocator> & y) noexcept {
-    return x > basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator>(const std::basic_string<charT, traits, Allocator> & x,
-                      basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) > y;
-}
-
-template<typename charT, typename traits>
-inline bool operator>(basic_string_view<charT, traits> x,
-                      const charT * y) noexcept {
-    return x > basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator>(const charT * x,
-                      basic_string_view<charT, traits> y) noexcept {
-return basic_string_view<charT, traits>(x) > y;
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator<=(basic_string_view<charT, traits> x,
-                       const std::basic_string<charT, traits, Allocator> & y) noexcept {
-return x <= basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator<=(const std::basic_string<charT, traits, Allocator> & x,
-                       basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) <= y;
-}
-
-template<typename charT, typename traits>
-inline bool operator<=(basic_string_view<charT, traits> x,
-                       const charT * y) noexcept {
-    return x <= basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator<=(const charT * x,
-                       basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) <= y;
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator>=(basic_string_view<charT, traits> x,
-                       const std::basic_string<charT, traits, Allocator> & y) noexcept {
-    return x >= basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits, typename Allocator>
-inline bool operator>=(const std::basic_string<charT, traits, Allocator> & x,
-                       basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) >= y;
-}
-
-template<typename charT, typename traits>
-inline bool operator>=(basic_string_view<charT, traits> x,
-                       const charT * y) noexcept {
-    return x >= basic_string_view<charT, traits>(y);
-}
-
-template<typename charT, typename traits>
-inline bool operator>=(const charT * x,
-                       basic_string_view<charT, traits> y) noexcept {
-    return basic_string_view<charT, traits>(x) >= y;
-}
-
-namespace detail {
-    
-    template<class charT, class traits>
-    inline void sv_insert_fill_chars(std::basic_ostream<charT, traits>& os, std::size_t n) {
-        enum { chunk_size = 8 };
-        charT fill_chars[chunk_size];
-        std::fill_n(fill_chars, static_cast< std::size_t >(chunk_size), os.fill());
-        for (; n >= chunk_size && os.good(); n -= chunk_size)
-            os.write(fill_chars, static_cast< std::size_t >(chunk_size));
-        if (n > 0 && os.good())
-            os.write(fill_chars, n);
-    }
-    
-    template<class charT, class traits>
-    void sv_insert_aligned(std::basic_ostream<charT, traits>& os, const basic_string_view<charT,traits>& str) {
-        const std::size_t size = str.size();
-        const std::size_t alignment_size = static_cast< std::size_t >(os.width()) - size;
-        const bool align_left = (os.flags() & std::basic_ostream<charT, traits>::adjustfield) == std::basic_ostream<charT, traits>::left;
-        if (!align_left) {
-            detail::sv_insert_fill_chars(os, alignment_size);
-            if (os.good())
-                os.write(str.data(), size);
-        }
-        else {
-            os.write(str.data(), size);
-            if (os.good())
-                detail::sv_insert_fill_chars(os, alignment_size);
-        }
-    }
-    
-} // namespace detail
-
-// Inserter
-template<class charT, class traits>
-inline std::basic_ostream<charT, traits>&
-operator<<(std::basic_ostream<charT, traits>& os,
-           const basic_string_view<charT,traits>& str) {
-    if (os.good()) {
-        const std::size_t size = str.size();
-        const std::size_t w = static_cast< std::size_t >(os.width());
-        if (w <= size)
-            os.write(str.data(), size);
-        else
-            detail::sv_insert_aligned(os, str);
-        os.width(0);
-    }
-    return os;
-}
-
-#if 0
-// numeric conversions
-//
-//  These are short-term implementations.
-//  In a production environment, I would rather avoid the copying.
-//
-inline int stoi (string_view str, size_t* idx=0, int base=10) {
-    return std::stoi ( std::string(str), idx, base );
-}
-
-inline long stol (string_view str, size_t* idx=0, int base=10) {
-    return std::stol ( std::string(str), idx, base );
-}
-
-inline unsigned long stoul (string_view str, size_t* idx=0, int base=10) {
-    return std::stoul ( std::string(str), idx, base );
-}
-
-inline long long stoll (string_view str, size_t* idx=0, int base=10) {
-    return std::stoll ( std::string(str), idx, base );
-}
-
-inline unsigned long long stoull (string_view str, size_t* idx=0, int base=10) {
-    return std::stoull ( std::string(str), idx, base );
-}
-
-inline float stof (string_view str, size_t* idx=0) {
-    return std::stof ( std::string(str), idx );
-}
-
-inline double stod (string_view str, size_t* idx=0) {
-    return std::stod ( std::string(str), idx );
-}
-
-inline long double stold (string_view str, size_t* idx=0)  {
-    return std::stold ( std::string(str), idx );
-}
-
-inline int  stoi (wstring_view str, size_t* idx=0, int base=10) {
-    return std::stoi ( std::wstring(str), idx, base );
-}
-
-inline long stol (wstring_view str, size_t* idx=0, int base=10) {
-    return std::stol ( std::wstring(str), idx, base );
-}
-
-inline unsigned long stoul (wstring_view str, size_t* idx=0, int base=10) {
-    return std::stoul ( std::wstring(str), idx, base );
-}
-
-inline long long stoll (wstring_view str, size_t* idx=0, int base=10) {
-    return std::stoll ( std::wstring(str), idx, base );
-}
-
-inline unsigned long long stoull (wstring_view str, size_t* idx=0, int base=10) {
-    return std::stoull ( std::wstring(str), idx, base );
-}
-
-inline float  stof (wstring_view str, size_t* idx=0) {
-    return std::stof ( std::wstring(str), idx );
-}
-
-inline double stod (wstring_view str, size_t* idx=0) {
-    return std::stod ( std::wstring(str), idx );
-}
-
-inline long double stold (wstring_view str, size_t* idx=0) {
-    return std::stold ( std::wstring(str), idx );
-}
-#endif
-
-}
-
-#if 0
-namespace std {
-    // Hashing
-    template<> struct hash<boost::string_view>;
-    template<> struct hash<boost::u16string_view>;
-    template<> struct hash<boost::u32string_view>;
-    template<> struct hash<boost::wstring_view>;
-}
-#endif
-
-#endif
diff --git a/Application/src/commons/common/misc/vec2.h b/Application/src/commons/common/misc/vec2.h
index 372f658a23a0e07dcc55a0cd66f70227e6cc28c8..c677cdc6f41350d9fa9a9bb36b744797ac26c16b 100644
--- a/Application/src/commons/common/misc/vec2.h
+++ b/Application/src/commons/common/misc/vec2.h
@@ -55,7 +55,7 @@ namespace cmn {
         {}
         
         template<typename T>
-        operator cv::Point_<T>() const { return cv::Point_<T>(A(), B()); }
+        operator cv::Point_<T>() const { return cv::Point_<T>((int)A(), (int)B()); }
         
         operator const Float2<!is_size>&() const { return *((const Float2<!is_size>*)this); }
         operator Float2<!is_size>&() { return *((Float2<!is_size>*)this); }
@@ -97,7 +97,7 @@ namespace cmn {
         }
         
         static constexpr inline bool almost_equal(Float2_t a, Float2_t b) {
-            constexpr Float2_t epsilon = 0.001;
+            constexpr auto epsilon = Float2_t(0.001);
             return cmn::abs(a - b) <= epsilon;
         }
         
@@ -258,7 +258,7 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
     
     TEMPLATE_FLOAT2
     inline std::ostream &operator <<(std::ostream &os, const T& obj) {
-        uint _x = roundf(obj.A()), _y = roundf(obj.B());
+        uint _x = (uint)roundf(obj.A()), _y = (uint)roundf(obj.B());
         //assert(obj.A() >= SHRT_MIN && obj.B() >= SHRT_MIN && obj.A() <= SHRT_MAX && obj.B() <= SHRT_MAX);
         
         uint both = (_x << 16) & 0xFFFF0000;
@@ -316,7 +316,7 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
         Bounds(const cv::Rect_<T>& rect) : Bounds(rect.x, rect.y, rect.width, rect.height) {}
         
         template<typename T>
-        operator cv::Rect_<T>() const { return cv::Rect_<T>(x, y, width, height); }
+        operator cv::Rect_<T>() const { return cv::Rect_<T>((int)x, (int)y, (int)width, (int)height); }
         
         constexpr const Vec2& pos() const { return this->_pos; }
         constexpr Vec2& pos() { return this->_pos; }
@@ -415,8 +415,9 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
         
     inline bool pnpoly(const std::vector<Vec2>& pts, const Vec2& pt)
     {
-        int npol = (int)pts.size();
-        int i, j;
+        assert(pts.size() < std::numeric_limits<int>::max());
+        size_t npol = pts.size();
+        size_t i, j;
         bool c = false;
         for (i = 0, j = npol-1; i < npol; j = i++) {
             if ((((pts[i].y <= pt.y) && (pt.y < pts[j].y)) ||
@@ -454,12 +455,12 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
         if(count > 2 && count <= 64) {
             // No hulls with less than 3 vertices (ensure actual polygon)
             assert( count > 2 && count <= 64 );
-            count = std::min( (int32_t)count, 64 );
+            count = std::min( count, 64u );
             auto _points = std::make_shared<std::vector<Vec2>>();
             _points->resize(count);
             
             // Find the right most point on the hull
-            int32_t rightMost = 0;
+            uint32_t rightMost = 0;
             double highestXCoord = (*_vertices)[0].x;
             for(uint32_t i = 1; i < count; ++i)
             {
@@ -476,9 +477,9 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
                         rightMost = i;
             }
             
-            int32_t hull[64];
-            int32_t outCount = 0;
-            int32_t indexHull = rightMost;
+            uint32_t hull[64];
+            uint32_t outCount = 0;
+            uint32_t indexHull = rightMost;
             
             for (;;)
             {
@@ -487,8 +488,8 @@ constexpr inline T operator SIGN(Float2_t s, const T& v) { return T(s SIGN v.A()
                 // Search for next index that wraps around the hull
                 // by computing cross products to find the most counter-clockwise
                 // vertex in the set, given the previos hull index
-                int32_t nextHullIndex = 0;
-                for(int32_t i = 1; i < (int32_t)count; ++i)
+                uint32_t nextHullIndex = 0;
+                for(uint32_t i = 1; i < count; ++i)
                 {
                     // Skip if same coordinate as we need three unique
                     // points in the set to perform a cross product
diff --git a/Application/src/commons/common/types.h b/Application/src/commons/common/types.h
index bdcefbb9a530dc7245aab3e0cfade318a318f1dc..2be9394fd45f4456d9a0dcfafa1484c1ce7fedb1 100644
--- a/Application/src/commons/common/types.h
+++ b/Application/src/commons/common/types.h
@@ -18,14 +18,6 @@
 namespace cmn {
 typedef std::vector<std::tuple<std::shared_ptr<std::vector<HorizontalLine>>, std::shared_ptr<std::vector<uchar>>>> blobs_t;
 constexpr int CV_MAX_THICKNESS = 32767;
-
-template< class T >
-struct remove_cvref {
-    typedef std::remove_cv_t<std::remove_reference_t<T>> type;
-};
-
-template< class T >
-using remove_cvref_t = typename remove_cvref<T>::type;
 }
 
 
diff --git a/Application/src/commons/common/video/GenericVideo.cpp b/Application/src/commons/common/video/GenericVideo.cpp
index 346456b5e3bfa56efa72a9384f8ec4c158e3fc10..8c3bb02d61838b22771f65db1b43398b4ce56c44 100644
--- a/Application/src/commons/common/video/GenericVideo.cpp
+++ b/Application/src/commons/common/video/GenericVideo.cpp
@@ -19,6 +19,41 @@ CropOffsets GenericVideo::crop_offsets() const {
     return SETTING(crop_offsets);
 }
 
+std::unique_ptr<cmn::Image> AveragingAccumulator::finalize() {
+    auto image = std::make_unique<cmn::Image>(_accumulator.rows, _accumulator.cols, 1);
+    
+    if(_mode == averaging_method_t::mean) {
+        cv::divide(_accumulator, cv::Scalar(count), _local);
+        _local.convertTo(image->get(), CV_8UC1);
+        
+    } else if(_mode == averaging_method_t::mode) {
+        _accumulator.copyTo(image->get());
+        
+        auto ptr = image->data();
+        const auto end = image->data() + image->cols * image->rows;
+        auto array_ptr = spatial_histogram.data();
+        
+        for (; ptr != end; ++ptr, ++array_ptr) {
+            uint8_t max_code = 0;
+            uint8_t max_number = 0;
+            uint8_t N = narrow_cast<uint8_t>(array_ptr->size());
+            //for(auto && [code, number] : *array_ptr) {
+            for(uint8_t code=0; code<N; ++code) {
+                const auto& number = (*array_ptr)[code];
+                if(number > max_number) {
+                    max_number = number;
+                    max_code = code;
+                }
+            }
+            
+            *ptr = max_code;
+        }
+    } else
+        _accumulator.copyTo(image->get());
+    
+    return std::move(image);
+}
+
 void GenericVideo::undistort(const gpuMat& disp, gpuMat &image) const {
     if (GlobalSettings::map().has("cam_undistort") && SETTING(cam_undistort)) {
         static cv::Mat map1;
@@ -119,13 +154,13 @@ void GenericVideo::generate_average(cv::Mat &av, uint64_t frameIndex) {
     Debug("Generating average for frame %d (method='%s')...", frameIndex, accumulator.mode().name());
     
     double count = 0;
-    float samples = GlobalSettings::has("average_samples") ? SETTING(average_samples).value<int>() : (length() * 0.01);
-    const int step = max(1, length() / samples);
+    float samples = GlobalSettings::has("average_samples") ? (float)SETTING(average_samples).value<uint32_t>() : (length() * 0.1f);
+    const auto step = narrow_cast<uint>(max(1, length() / samples));
     
     cv::Mat f;
     uint64_t counted = 0;
     for(long_t i=length() ? length()-1 : 0; i>=0; i-=step) {
-        frame(i, f);
+        frame((uint64_t)i, f);
         
         assert(f.channels() == 1);
         accumulator.add(f);
diff --git a/Application/src/commons/common/video/GenericVideo.h b/Application/src/commons/common/video/GenericVideo.h
index 2c10ddce87a887a39b6df887c4f995563d2dcefd..66e71c3a380ae2e4dd06b6a136a1f90bd58684cd 100644
--- a/Application/src/commons/common/video/GenericVideo.h
+++ b/Application/src/commons/common/video/GenericVideo.h
@@ -10,8 +10,10 @@ namespace cmn {
 ENUM_CLASS(averaging_method_t, mean, mode, max, min);
 ENUM_CLASS_HAS_DOCS(averaging_method_t);
 
-template<typename Mat = cv::Mat, bool threaded = false>
 class AveragingAccumulator {
+public:
+    using Mat = cv::Mat;
+    
 protected:
     GETTER(averaging_method_t::Class, mode)
     Mat _accumulator;
@@ -33,6 +35,7 @@ public:
         : _mode(mode)
     { }
     
+    template<bool threaded = false>
     void add(const Mat &f) {
         assert(f.channels() == 1);
         assert(f.type() == CV_8UC1);
@@ -40,12 +43,12 @@ public:
         // initialization code
         if(_accumulator.empty()) {
             _size = Size2(f.cols, f.rows);
-            _accumulator = cv::Mat::zeros(_size.height, _size.width, _mode == averaging_method_t::mean ? CV_32FC1 : CV_8UC1);
+            _accumulator = cv::Mat::zeros((int)_size.height, (int)_size.width, _mode == averaging_method_t::mean ? CV_32FC1 : CV_8UC1);
             if(_mode == averaging_method_t::min)
                 _accumulator.setTo(255);
             
             if(_mode == averaging_method_t::mode) {
-                spatial_histogram.resize(f.cols * f.rows);
+                spatial_histogram.resize(size_t(f.cols) * size_t(f.rows));
                 for(uint64_t i=0; i<spatial_histogram.size(); ++i) {
                     std::fill(spatial_histogram.at(i).begin(), spatial_histogram.at(i).end(), 0);
                     spatial_mutex.push_back(std::make_unique<std::mutex>());
@@ -87,39 +90,7 @@ public:
             U_EXCEPTION("Unknown averaging_method '%s'.", _mode.name())
     }
     
-    std::unique_ptr<cmn::Image> finalize() {
-        auto image = std::make_unique<cmn::Image>(_accumulator.rows, _accumulator.cols, 1);
-        
-        if(_mode == averaging_method_t::mean) {
-            cv::divide(_accumulator, cv::Scalar(count), _local);
-            _local.convertTo(image->get(), CV_8UC1);
-            
-        } else if(_mode == averaging_method_t::mode) {
-            _accumulator.copyTo(image->get());
-            
-            auto ptr = image->data();
-            const auto end = image->data() + image->cols * image->rows;
-            auto array_ptr = spatial_histogram.data();
-            
-            for (; ptr != end; ++ptr, ++array_ptr) {
-                uchar max_code = 0;
-                uint8_t max_number = 0;
-                //for(auto && [code, number] : *array_ptr) {
-                for(uint64_t code=0; code<array_ptr->size(); ++code) {
-                    const auto& number = (*array_ptr)[code];
-                    if(number > max_number) {
-                        max_number = number;
-                        max_code = code;
-                    }
-                }
-                
-                *ptr = max_code;
-            }
-        } else
-            _accumulator.copyTo(image->get());
-        
-        return std::move(image);
-    }
+    std::unique_ptr<cmn::Image> finalize();
 };
 
 }
diff --git a/Application/src/commons/common/video/VideoSource.cpp b/Application/src/commons/common/video/VideoSource.cpp
index 14fd6ceadcbc5c0628625762cc26b227d50f7554..d9ca985f9569dba8d335259ccfff338d430e3df1 100644
--- a/Application/src/commons/common/video/VideoSource.cpp
+++ b/Application/src/commons/common/video/VideoSource.cpp
@@ -24,7 +24,7 @@ std::string VideoSource::File::complete_name(const std::string &basename, const
     return basename + "." + ext;
 }
 
-VideoSource::File * VideoSource::File::open(long_t index, const std::string& basename, const std::string& ext, bool no_check) {
+VideoSource::File * VideoSource::File::open(size_t index, const std::string& basename, const std::string& ext, bool no_check) {
     if(no_check) {
         return new File(index, basename, ext);
     }
@@ -38,7 +38,7 @@ VideoSource::File * VideoSource::File::open(long_t index, const std::string& bas
     return NULL;
 }
 
-VideoSource::File::File(long_t index, const std::string& basename, const std::string& extension) : _index(index), _video(NULL), _size(0, 0) {
+VideoSource::File::File(size_t index, const std::string& basename, const std::string& extension) : _index(index), _video(NULL), _size(0, 0) {
     _filename = complete_name(basename, extension);
     
     // check the extension(-type)
@@ -68,7 +68,7 @@ VideoSource::File::File(long_t index, const std::string& basename, const std::st
                     _timestamps = cnpy::npz_load(npz.str(), "frame_time").as_vec<double>();
                     auto res = cnpy::npz_load(npz.str(), "imgshape").as_vec<int64_t>();
                     _size = cv::Size( (int)res[1], (int)res[0] );
-                    _length = (long_t)_timestamps.size();
+                    _length = _timestamps.size();
                 } catch(...) {
                     Except("Failed opening NPZ archive '%S' with (presumably) timestamps in them for video '%S'. Proceeding without.", &npz.str(), &_filename);
                     
@@ -88,7 +88,7 @@ VideoSource::File::File(long_t index, const std::string& basename, const std::st
         }
             
         case IMAGE:
-            _length = 1;
+            _length = 1u;
             break;
             
         default:
@@ -156,7 +156,7 @@ short VideoSource::File::framerate() {
             _video->open(_filename);
         auto fps = _video->framerate();
         _video->close();
-        return fps;
+        return narrow_cast<short>(fps);
     }
 }
 
@@ -172,7 +172,7 @@ uint64_t VideoSource::File::timestamp(uint64_t frameIndex) const {
     auto duration = std::chrono::duration_cast<std::chrono::nanoseconds>(point);
     //uint64_t seconds = std::chrono::duration_cast<std::chrono::seconds>(duration).count();
     //uint64_t ms = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
-    uint64_t ns = std::chrono::duration_cast<std::chrono::microseconds>(duration).count();
+    auto ns = narrow_cast<uint64_t>(std::chrono::duration_cast<std::chrono::microseconds>(duration).count());
     return ns;
 }
 
@@ -226,7 +226,7 @@ VideoSource::VideoSource(const std::string& source) {
     if(std::regex_search(source,m,rext)) {
         auto x = m[1];
         extension = x.str().substr(1);
-        base_name = source.substr(0, m.position(1));
+        base_name = source.substr(0u, (uint64_t)m.position(1));
         
         Debug("Extension '%S' basename '%S'", &extension, &base_name);
         
@@ -238,7 +238,7 @@ VideoSource::VideoSource(const std::string& source) {
         auto x = m[0];
         
         std::string s = x.str();
-        auto p = m.position();
+        auto p = (uint64_t)m.position();
         
         s = s.substr(1, s.length()-2);
         auto split = utils::split(s, '.');
@@ -251,7 +251,7 @@ VideoSource::VideoSource(const std::string& source) {
         }
         
         number_length = std::stoi(split[0]);
-        base_name = base_name.substr(0, p);
+        base_name = base_name.substr(0u, p);
         Debug("match '%S' at %d with nr %d", &s, p, number_length);
     }
     
@@ -266,14 +266,14 @@ VideoSource::VideoSource(const std::string& source) {
 VideoSource::VideoSource(const std::vector<file::Path>& files)
 {
     for(auto &path : files) {
-        auto extension = path.extension().to_string();
+        auto extension = std::string(path.extension());
         auto basename = path.remove_extension().str();
         auto f = File::open(_files_in_seq.size(), basename, extension);
         if(!f)
             U_EXCEPTION("Cannot open file '%S'.", &path.str());
         
         _files_in_seq.push_back(f);
-        _length += (long_t)f->length();
+        _length += f->length();
     }
     
     if(_files_in_seq.empty()) {
@@ -296,13 +296,13 @@ void VideoSource::open(const std::string& basename, const std::string& extension
 
         if(f) {
             _files_in_seq.push_back(f);
-            _length += (long_t)f->length();
+            _length += f->length();
         } else {
             U_EXCEPTION("Input source '%S' not found.", &basename);
         }
         
     } else if(seq_end == VIDEO_SEQUENCE_UNSPECIFIED_VALUE) {
-        auto base = file::Path(basename).is_folder() ? "" : file::Path(basename).filename().to_string();
+        auto base = file::Path(basename).is_folder() ? "" : file::Path(basename).filename();
         Debug("Trying to find the last file (starting at %d) pattern '%S%%%dd.%S'...", seq_start, &base, padding, &extension);
         
         _files_in_seq.reserve(10000);
@@ -313,7 +313,7 @@ void VideoSource::open(const std::string& basename, const std::string& extension
             
             try {
                 ss << basename << std::setfill('0') << std::setw(padding) << i;
-                File *file = File::open(i - seq_start, ss.str(), extension);
+                File *file = File::open(sign_cast<size_t>(i - seq_start), ss.str(), extension);
                 if(!file) {
                     break;
                 }
@@ -515,8 +515,8 @@ void VideoSource::generate_average(cv::Mat &av, uint64_t) {
             float_mat = gpuMat::zeros(average.rows, average.cols, CV_8UC1);
     }
     
-    float samples = GlobalSettings::has("average_samples") ? SETTING(average_samples).value<int>() : (length() * 0.01);
-    uint64_t step = max(1, _files_in_seq.size() < samples ? 1 : ceil(_files_in_seq.size() / samples));
+    float samples = GlobalSettings::has("average_samples") ? (float)SETTING(average_samples).value<uint32_t>() : (length() * 0.01f);
+    uint64_t step = max(1u, _files_in_seq.size() < samples ? 1u : (uint64_t)ceil(_files_in_seq.size() / samples));
     uint64_t frames_per_file = max(1, _files_in_seq.size() < samples ? (length() / _files_in_seq.size()) / (length() / samples) : 1);
     
     if(samples > 255 && method == averaging_method_t::mode)
@@ -527,7 +527,7 @@ void VideoSource::generate_average(cv::Mat &av, uint64_t) {
     std::vector<std::array<uint8_t, 256>> spatial_histogram;
     std::vector<std::unique_ptr<std::mutex>> spatial_mutex;
     if(method == averaging_method_t::mode) {
-        spatial_histogram.resize(average.cols * average.rows);
+        spatial_histogram.resize(size_t(average.cols) * size_t(average.rows));
         for(uint64_t i=0; i<spatial_histogram.size(); ++i) {
             std::fill(spatial_histogram.at(i).begin(), spatial_histogram.at(i).end(), 0);
             spatial_mutex.push_back(std::make_unique<std::mutex>());
@@ -542,7 +542,7 @@ void VideoSource::generate_average(cv::Mat &av, uint64_t) {
         auto file = _files_in_seq.at(i);
         file_indexes[file].insert(0);
         if(frames_per_file > 1) {
-            auto step = max(1, ceil(file->length() / frames_per_file));
+            auto step = max(1u, (uint64_t)ceil((uint64_t)file->length() / frames_per_file));
             for(uint64_t i=step; i<(uint64_t)file->length(); i+= step) {
                 file_indexes[file].insert(i);
             }
diff --git a/Application/src/commons/common/video/VideoSource.h b/Application/src/commons/common/video/VideoSource.h
index e10fd1d9a9cece6b93fb32f83ab786a1d78d9dbe..6310f0ebb07981f1fb4d962155a3a7a6b286e3f2 100644
--- a/Application/src/commons/common/video/VideoSource.h
+++ b/Application/src/commons/common/video/VideoSource.h
@@ -23,15 +23,15 @@ public:
             IMAGE
         };
         
-        static File *open(long_t index, const std::string& basename, const std::string& ext, bool no_check = false);
+        static File *open(size_t index, const std::string& basename, const std::string& ext, bool no_check = false);
         static std::string complete_name(const std::string& basename, const std::string& ext);
         
     private:
         static std::vector<std::pair<std::string, Type>> _extensions;
         
-        GETTER(long_t, index)
+        GETTER(size_t, index)
         GETTER(std::string, filename)
-        long_t _length;
+        size_t _length;
         Video *_video;
         Type _type;
         
@@ -39,11 +39,11 @@ public:
         cv::Size _size;
         
     private:
-        File(long_t index, const std::string& basename, const std::string& extension);
+        File(size_t index, const std::string& basename, const std::string& extension);
         
     public:
         ~File();
-        long_t length() const { return _length; }
+        size_t length() const { return _length; }
         const cv::Size& resolution();
         
         void frame(long_t frameIndex, cv::Mat& output, bool lazy_video = false) const;
diff --git a/Application/src/grabber/default_config.cpp b/Application/src/grabber/default_config.cpp
index 8e4e01e95cad1cf1d3e00be67b414724b93039fb..ae4ca5554766207eb6da5404ccda2d041d0aa8a2 100644
--- a/Application/src/grabber/default_config.cpp
+++ b/Application/src/grabber/default_config.cpp
@@ -53,13 +53,13 @@ namespace default_config {
         Adding adding(config, docs, fn);
         
         std::vector<float> buffer {
-            -0.2576632 , -0.19233586,  0.00245493,  0.00398822,  0.35924019
+            -0.2576632f , -0.19233586f,  0.00245493f,  0.00398822f,  0.35924019f
         };
         
         std::vector<float> matrix = {
-            2.94508959e+03,   0.00000000e+00,   6.17255441e+02,
-            0.00000000e+00,   2.94282514e+03,   6.82473623e+02,
-            0.00000000e+00,   0.00000000e+00,   1.00000000e+00
+            2.94508959e+03f,   0.00000000e+00f,   6.17255441e+02f,
+            0.00000000e+00f,   2.94282514e+03f,   6.82473623e+02f,
+            0.00000000e+00f,   0.00000000e+00f,   1.00000000e+00f
         };
         
         CONFIG("cam_undistort_vector", buffer, "");
@@ -77,7 +77,7 @@ namespace default_config {
         CONFIG("system_memory_limit", uint64_t(0), "Custom override of how many bytes of system RAM the program is allowed to fill. If `approximate_length_minutes` or `stop_after_minutes` are set, this might help to increase the resulting RAW video footage frame_rate.");
         
         CONFIG("frame_rate", int(-1), "Frame rate of the video will be set according to `cam_framerate` or the framerate of a given video for conversion.");
-        CONFIG("blob_size_range", Rangef(0.01, 500000), "Minimum or maximum size of the individuals on screen after thresholding. Anything smaller or bigger than these values will be disregarded as noise.");
+        CONFIG("blob_size_range", Rangef(0.01f, 500000.f), "Minimum or maximum size of the individuals on screen after thresholding. Anything smaller or bigger than these values will be disregarded as noise.");
         CONFIG("crop_offsets", CropOffsets(), "Percentage offsets [left, top, right, bottom] that will be cut off the input images (e.g. [0.1,0.1,0.5,0.5] will remove 10%% from the left and top and 50%% from the right and bottom and the video will be 60%% smaller in X and Y).");
         CONFIG("crop_window", false, "If set to true, the grabber will open a window before the analysis starts where the user can drag+drop points defining the crop_offsets.");
         
diff --git a/Application/src/grabber/grabber.cpp b/Application/src/grabber/grabber.cpp
index 39e965c05b1b223fe006de936fc281ace56a3423..d5686f44d2b52ec6d1027825b2fece69199ad92d 100644
--- a/Application/src/grabber/grabber.cpp
+++ b/Application/src/grabber/grabber.cpp
@@ -289,7 +289,7 @@ FrameGrabber::FrameGrabber(std::function<void(FrameGrabber&)> callback_before_st
   : //_current_image(NULL),
     _current_average_timestamp(0),
     _average_finished(false),
-    _average_samples(0), _last_index(0),
+    _average_samples(0u), _last_index(0),
     _video(NULL), _video_mask(NULL),
     _camera(NULL),
     _current_fps(0), _fps(0),
@@ -798,7 +798,7 @@ bool FrameGrabber::add_image_to_average(const Image_t& current) {
             
             // to protect _last_frame
             std::lock_guard<std::mutex> guard(_frame_lock);
-            _average_samples = 0;
+            _average_samples = 0u;
             _average_finished = false;
             if(fname.exists()) {
                 if(!fname.delete_file()) {
@@ -845,7 +845,7 @@ bool FrameGrabber::add_image_to_average(const Image_t& current) {
         
         _average_samples++;
         
-        if(_average_samples >= SETTING(average_samples).value<int>()) { //|| fname.is_regular()) {
+        if(_average_samples >= SETTING(average_samples).value<uint32_t>()) { //|| fname.is_regular()) {
             if(use_mean) {
                 _current_average /= float(_average_samples);
                 std::lock_guard<std::mutex> guard(_frame_lock);
diff --git a/Application/src/grabber/grabber.h b/Application/src/grabber/grabber.h
index 11faec7c7a892dc9be6086c33e35943aca9e4033..bbba40146246545c7668714e2f3b745501a474d3 100644
--- a/Application/src/grabber/grabber.h
+++ b/Application/src/grabber/grabber.h
@@ -137,7 +137,7 @@ protected:
     std::atomic<double> _tracking_time, _saving_time;
     
     GETTER(std::atomic_bool, average_finished)
-    GETTER(long, average_samples)
+    GETTER(uint32_t, average_samples)
     GETTER(std::atomic_long, last_index)
     
     //std::chrono::time_point<Image::clock_> _start_timing;
diff --git a/Application/src/grabber/gui.cpp b/Application/src/grabber/gui.cpp
index 6d55db0fe1ae0064032ed3450f25b5667e1ff719..1dd9b1b37c1ab386ea84001b9b55dbe6fbeeb93f 100644
--- a/Application/src/grabber/gui.cpp
+++ b/Application/src/grabber/gui.cpp
@@ -336,7 +336,7 @@ void GUI::draw(gui::DrawStructure &base) {
                 base.wrap_object(*background);
             }
             
-            base.text("generating average ("+std::to_string(_grabber.average_samples())+"/"+std::to_string(SETTING(average_samples).value<int>())+")", Vec2(_size.width/2, _size.height/2), Red, Font(0.8, Align::Center), base.scale().reciprocal());
+            base.text("generating average ("+std::to_string(_grabber.average_samples())+"/"+std::to_string(SETTING(average_samples).value<uint32_t>())+")", Vec2(_size.width/2, _size.height/2), Red, Font(0.8, Align::Center), base.scale().reciprocal());
         } else {
             base.text("waiting for frame...", Vec2(_size.width/2, _size.height/2), Red, Font(0.8, Align::Center), base.scale().reciprocal());
         }
diff --git a/Application/src/tracker/VideoOpener.cpp b/Application/src/tracker/VideoOpener.cpp
index e02915b31d1542cc59808654e2288cd0ff5527b2..53f1dcdcd2aa5568b8563d5ab34587b03769a20a 100644
--- a/Application/src/tracker/VideoOpener.cpp
+++ b/Application/src/tracker/VideoOpener.cpp
@@ -24,7 +24,7 @@ VideoOpener::LabeledCheckbox::LabeledCheckbox(const std::string& name)
     _docs = gui::temp_docs[name];
     
     _checkbox->set_checked(_ref.value<bool>());
-    _checkbox->set_font(Font(0.6));
+    _checkbox->set_font(Font(0.6f));
 
     _checkbox->on_change([this](){
         try {
@@ -44,7 +44,7 @@ VideoOpener::LabeledTextField::LabeledTextField(const std::string& name)
       _ref(gui::temp_settings[name])
 {
     _text_field->set_placeholder(name);
-    _text_field->set_font(Font(0.6));
+    _text_field->set_font(Font(0.6f));
     
     _docs = gui::temp_docs[name];
 
@@ -68,7 +68,7 @@ VideoOpener::LabeledDropDown::LabeledDropDown(const std::string& name)
 {
     _docs = gui::temp_docs[name];
     
-    _dropdown->textfield()->set_font(Font(0.6));
+    _dropdown->textfield()->set_font(Font(0.6f));
     assert(_ref.get().is_enum());
     std::vector<Dropdown::TextItem> items;
     int index = 0;
@@ -76,19 +76,23 @@ VideoOpener::LabeledDropDown::LabeledDropDown(const std::string& name)
         items.push_back(Dropdown::TextItem(name, index++));
     }
     _dropdown->set_items(items);
-    _dropdown->select_item(_ref.get().enum_index()());
+    _dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
     _dropdown->textfield()->set_text(_ref.get().valueString());
     
     _dropdown->on_select([this](auto index, auto) {
+        if(index < 0)
+            return;
+        
         try {
-            _ref.get().set_value_from_string(_ref.get().enum_values()().at(index));
+            _ref.get().set_value_from_string(_ref.get().enum_values()().at((size_t)index));
         } catch(...) {}
+        
         _dropdown->set_opened(false);
     });
 }
 
 void VideoOpener::LabeledDropDown::update() {
-    _dropdown->select_item(_ref.get().enum_index()());
+    _dropdown->select_item(narrow_cast<long>(_ref.get().enum_index()()));
 }
 
 VideoOpener::VideoOpener() {
@@ -182,18 +186,18 @@ VideoOpener::VideoOpener() {
     _text_fields["cmd_parameters"] = std::make_unique<LabeledTextField>("cmd_parameters");
     
     std::vector<Layout::Ptr> objects{
-        Layout::Ptr(std::make_shared<Text>("Settings", Vec2(), White, gui::Font(0.8, Style::Bold)))
+        Layout::Ptr(std::make_shared<Text>("Settings", Vec2(), White, gui::Font(0.8f, Style::Bold)))
     };
     for(auto &[key, ptr] : _text_fields)
         ptr->add_to(objects);
     
     _raw_settings->set_children(objects);
     
-    _loading_text = std::make_shared<gui::Text>("generating average", Vec2(100,0), Cyan, gui::Font(0.5));
+    _loading_text = std::make_shared<gui::Text>("generating average", Vec2(100,0), Cyan, gui::Font(0.5f));
     
-    _raw_description = std::make_shared<gui::StaticText>("Info", Vec2(), Size2(500, -1), Font(0.6));
+    _raw_description = std::make_shared<gui::StaticText>("Info", Vec2(), Size2(500, -1), Font(0.6f));
     _raw_info->set_children({
-        Layout::Ptr(std::make_shared<Text>("Preview", Vec2(), White, gui::Font(0.8, Style::Bold))),
+        Layout::Ptr(std::make_shared<Text>("Preview", Vec2(), White, gui::Font(0.8f, Style::Bold))),
         _screenshot,
         _raw_description
     });
@@ -350,9 +354,9 @@ VideoOpener::VideoOpener() {
             if(image) {
                 _screenshot->set_source(std::move(image));
                 
-                const auto mw = _file_chooser->graph()->width() * 0.3;
+                const auto mw = _file_chooser->graph()->width() * 0.3f;
                 if(_raw_description->max_size().x != mw) {
-                    _raw_description->set_max_size(Size2(mw, -1));
+                    _raw_description->set_max_size(Size2(mw, -1.f));
                     _screenshot_previous_size = 0;
                 }
                 
@@ -476,7 +480,7 @@ void VideoOpener::BufferedVideo::restart_background() {
         
         std::unique_ptr<VideoSource> background_video;
         uint64_t background_video_index = 0;
-        std::unique_ptr<AveragingAccumulator<>> accumulator;
+        std::unique_ptr<AveragingAccumulator> accumulator;
         
         { // open video and load first frame
             background_video = std::make_unique<VideoSource>(_path.str());
@@ -488,13 +492,13 @@ void VideoOpener::BufferedVideo::restart_background() {
                 resize_image(img, 500 / double(max(img.cols, img.rows)));
             
             background_video_index = 0;
-            accumulator = std::make_unique<AveragingAccumulator<>>(TEMP_SETTING(averaging_method).value<averaging_method_t::Class>());
+            accumulator = std::make_unique<AveragingAccumulator>(TEMP_SETTING(averaging_method).value<averaging_method_t::Class>());
             accumulator->add(img);
         }
         
         _terminated_background_task = false;
         
-        int step = max(1, int(background_video->length() / max(2.0, double(TEMP_SETTING(average_samples).value<int>()))));
+        uint step = max(1u, uint(background_video->length() / max(2u, uint(TEMP_SETTING(average_samples).value<int>()))));
         cv::Mat flt, img;
         _number_samples = 0;
         
@@ -665,7 +669,7 @@ void VideoOpener::select_file(const file::Path &p) {
                 std::lock_guard guard(_video_mutex);
                 Except("Could not open file '%S'.", &p.str());
                 
-                cv::Mat img = cv::Mat::zeros(max_width, max_width, CV_8UC1);
+                cv::Mat img = cv::Mat::zeros((int)max_width, (int)max_width, CV_8UC1);
                 cv::putText(img, "Cannot open video.", Vec2(50, 220), cv::FONT_HERSHEY_PLAIN, 1, White);
                 _screenshot->set_source(std::make_unique<Image>(img));
                 _screenshot->set_scale(Vec2(1));
@@ -687,7 +691,7 @@ void VideoOpener::select_file(const file::Path &p) {
                 if(p.has_extension())
                     filename = filename.remove_extension();
                 
-                if(utils::contains(p.filename().to_string(), '%')) {
+                if(utils::contains((std::string)p.filename(), '%')) {
                     filename = filename.remove_filename();
                 }
                 
@@ -753,7 +757,7 @@ void VideoOpener::select_file(const file::Path &p) {
     }
     
     std::vector<Layout::Ptr> children {
-        Layout::Ptr(std::make_shared<Text>("Settings", Vec2(), White, gui::Font(0.8, Style::Bold)))
+        Layout::Ptr(std::make_shared<Text>("Settings", Vec2(), White, gui::Font(0.8f, Style::Bold)))
     };
     
     for(auto &name : _settings_to_show) {
@@ -764,14 +768,14 @@ void VideoOpener::select_file(const file::Path &p) {
             start = tmp[name].get().valueString();
         
         if(tmp[name].is_type<bool>()) {
-            children.push_back( Layout::Ptr(std::make_shared<Checkbox>(Vec2(), name, tmp[name].get().value<bool>(), gui::Font(0.6))) );
+            children.push_back( Layout::Ptr(std::make_shared<Checkbox>(Vec2(), name, tmp[name].get().value<bool>(), gui::Font(0.6f))) );
         } else if(name == "output_prefix") {
             std::vector<std::string> folders;
             for(auto &p : _selected.remove_filename().find_files()) {
                 try {
                     if(p.is_folder() && p.filename() != "data" && p.filename() != "..") {
                         if(!p.find_files().empty()) {
-                            folders.push_back(p.filename().to_string());
+                            folders.push_back((std::string)p.filename());
                         }
                     }
                 } catch(const UtilsException& ex) {
@@ -779,14 +783,14 @@ void VideoOpener::select_file(const file::Path &p) {
                 }
             }
             
-            children.push_back( Layout::Ptr(std::make_shared<Text>(name, Vec2(), White, gui::Font(0.6))) );
+            children.push_back( Layout::Ptr(std::make_shared<Text>(name, Vec2(), White, gui::Font(0.6f))) );
             children.push_back( Layout::Ptr(std::make_shared<Dropdown>(Bounds(0, 0, 300, 28), folders)) );
-            ((Dropdown*)children.back().get())->textfield()->set_font(Font(0.6));
+            ((Dropdown*)children.back().get())->textfield()->set_font(Font(0.6f));
             
         } else {
-            children.push_back( Layout::Ptr(std::make_shared<Text>(name, Vec2(), White, gui::Font(0.6))) );
+            children.push_back( Layout::Ptr(std::make_shared<Text>(name, Vec2(), White, gui::Font(0.6f))) );
             children.push_back( Layout::Ptr(std::make_shared<Textfield>(start, Bounds(0, 0, 300, 28))));
-            ((Textfield*)children.back().get())->set_font(Font(0.6));
+            ((Textfield*)children.back().get())->set_font(Font(0.6f));
         }
         
         if(name == "output_prefix") {
@@ -815,9 +819,10 @@ void VideoOpener::select_file(const file::Path &p) {
                 ((Dropdown*)children.back().get())->select_item(-1);
             else {
                 auto items = ((Dropdown*)children.back().get())->items();
-                for(size_t i=0; i<items.size(); ++i) {
+                auto N = items.size();
+                for(size_t i=0; i<N; ++i) {
                     if(items.at(i).search_name() == _output_prefix) {
-                        ((Dropdown*)children.back().get())->select_item(i);
+                        ((Dropdown*)children.back().get())->select_item(narrow_cast<long>(i));
                         break;
                     }
                 }
@@ -833,10 +838,10 @@ void VideoOpener::select_file(const file::Path &p) {
     _load_results_checkbox = nullptr;
     auto path = Output::TrackingResults::expected_filename();
     if(path.exists()) {
-        children.push_back( Layout::Ptr(std::make_shared<Checkbox>(Vec2(), "load results", false, gui::Font(0.6))) );
+        children.push_back( Layout::Ptr(std::make_shared<Checkbox>(Vec2(), "load results", false, gui::Font(0.6f))) );
         _load_results_checkbox = dynamic_cast<Checkbox*>(children.back().get());
     } else
-        children.push_back( Layout::Ptr(std::make_shared<Text>("No loadable results found.", Vec2(), Gray, gui::Font(0.7, Style::Bold))) );
+        children.push_back( Layout::Ptr(std::make_shared<Text>("No loadable results found.", Vec2(), Gray, gui::Font(0.7f, Style::Bold))) );
     
     _extra->set_children(children);
     _extra->auto_size(Margin{0,0});
@@ -848,7 +853,7 @@ void VideoOpener::select_file(const file::Path &p) {
         auto text = video.get_info();
         
 
-        gui::derived_ptr<gui::Text> info_text = std::make_shared<gui::Text>("Selected", Vec2(), gui::White, gui::Font(0.8, gui::Style::Bold));
+        gui::derived_ptr<gui::Text> info_text = std::make_shared<gui::Text>("Selected", Vec2(), gui::White, gui::Font(0.8f, gui::Style::Bold));
         gui::derived_ptr<gui::StaticText> info_description = std::make_shared<gui::StaticText>(settings::htmlify(text), Vec2(), Size2(300, 600), gui::Font(0.5));
         
         _infos->set_children({
diff --git a/Application/src/tracker/VideoOpener.h b/Application/src/tracker/VideoOpener.h
index 5d88dee2655f590348c4035c6b16a861fd210102..61c720183a2264444c85e225be8dc96a02db42a9 100644
--- a/Application/src/tracker/VideoOpener.h
+++ b/Application/src/tracker/VideoOpener.h
@@ -41,7 +41,7 @@ public:
         std::unique_ptr<Image> _cached_frame;
         std::atomic<bool> _terminate = false, _terminate_background = false;
         
-        std::atomic<uint32_t> _threshold = 0;
+        std::atomic<int32_t> _threshold = 0;
         
         std::unique_ptr<std::thread> _update_thread;
         std::unique_ptr<std::thread> _background_thread;
@@ -84,7 +84,7 @@ public:
             : _text(std::make_shared<gui::Text>(name))
               //_joint(std::make_shared<gui::HorizontalLayout>(std::vector<Layout::Ptr>{_text, _text_field}))
         {
-            _text->set_font(Font(0.6));
+            _text->set_font(Font(0.6f));
             _text->set_color(White);
         }
         
diff --git a/Application/src/tracker/gui/DrawFish.cpp b/Application/src/tracker/gui/DrawFish.cpp
index fba088abe4f4511580ad13d89954b4f613f3eb7a..7a3b2ea130e0b0de0d187beb5b63efff9dfec143 100644
--- a/Application/src/tracker/gui/DrawFish.cpp
+++ b/Application/src/tracker/gui/DrawFish.cpp
@@ -352,7 +352,7 @@ CREATE_STRUCT(CachedGUIOptions,
                         auto && [dpos, difference] = b->difference_image(*Tracker::instance()->background(), 0);
                         auto rgba = std::make_unique<Image>(difference->rows, difference->cols, 4);
                         
-                        float maximum_grey = 0, minimum_grey = std::numeric_limits<float>::max();
+                        uchar maximum_grey = 0, minimum_grey = std::numeric_limits<uchar>::max();
                         for(size_t i=0; i<difference->size(); ++i) {
                             auto c = difference->data()[i];
                             maximum_grey = max(maximum_grey, c);
@@ -361,7 +361,7 @@ CREATE_STRUCT(CachedGUIOptions,
                                 minimum_grey = min(minimum_grey, c);
                         }
                         for(size_t i=0; i<difference->size(); ++i)
-                            difference->data()[i] = min(255, float(difference->data()[i]) / maximum_grey * 255);
+                            difference->data()[i] = (uchar)min(255, float(difference->data()[i]) / maximum_grey * 255);
                         
                         if(minimum_grey == maximum_grey)
                             minimum_grey = maximum_grey - 1;
@@ -400,12 +400,12 @@ CREATE_STRUCT(CachedGUIOptions,
                             
                             auto rgba = std::make_unique<Image>(image->rows, image->cols, 4);
                             
-                            float maximum = 0;
+                            uchar maximum = 0;
                             for(size_t i=0; i<difference->size(); ++i) {
                                 maximum = max(maximum, difference->data()[i]);
                             }
                             for(size_t i=0; i<difference->size(); ++i)
-                                difference->data()[i] = min(255, float(difference->data()[i]) / maximum * 255);
+                                difference->data()[i] = (uchar)min(255, float(difference->data()[i]) / maximum * 255);
                             
                             rgba->set_channels(image->data(), {0, 1, 2});
                             rgba->set_channel(3, difference->data());
diff --git a/Application/src/tracker/gui/IdentityHeatmap.cpp b/Application/src/tracker/gui/IdentityHeatmap.cpp
index 736258fb1f7ccb628b0366155fc2935fc6a63c13..6b28235899f722b8e54a10d5b16e0ec2d94b80d1 100644
--- a/Application/src/tracker/gui/IdentityHeatmap.cpp
+++ b/Application/src/tracker/gui/IdentityHeatmap.cpp
@@ -116,7 +116,7 @@ void HeatmapController::paint_heatmap() {
 void HeatmapController::save() {
     update_variables();
     
-    file::Path path = pv::DataLocation::parse("output", file::Path(SETTING(filename).value<file::Path>().filename().to_string()+ "_heatmap_"+Meta::toStr(uniform_grid_cell_size)+"_"+Meta::toStr(N)+"x"+Meta::toStr(N)+".npz"));
+    file::Path path = pv::DataLocation::parse("output", file::Path((std::string)SETTING(filename).value<file::Path>().filename()+ "_heatmap_"+Meta::toStr(uniform_grid_cell_size)+"_"+Meta::toStr(N)+"x"+Meta::toStr(N)+".npz"));
     DebugHeader("Saving heatmap to '%S'...", &path.str());
     
     _frame_context = 0;
@@ -134,7 +134,7 @@ void HeatmapController::save() {
     
     size_t count_frames = 0;
     size_t max_frames = Tracker::end_frame() - Tracker::start_frame();
-    size_t print_step = max_frames * 0.1 + 1;
+    size_t print_step = max_frames / 10 + 1;
     std::vector<long_t> frames;
     for(long_t frame = Tracker::start_frame(); frame <= Tracker::end_frame(); ++frame) {
         update_data(frame);
@@ -169,7 +169,7 @@ void HeatmapController::sort_data_into_custom_grid() {
     static Timer timer;
     timer.reset();
     
-    double minimum = 0, maximum = 0;
+    Float2_t minimum = 0, maximum = 0;
     std::vector<double> values;
     std::fill(_array_samples.begin(), _array_samples.end(), _normalization == normalization_t::cell ? 1 : 0);
     std::fill(_array_grid.begin(), _array_grid.end(), 0);
@@ -183,8 +183,8 @@ void HeatmapController::sort_data_into_custom_grid() {
             if(r.pixel_size() > uniform_grid_cell_size)
                 return true;
             
-            int64_t cx = (double((double)r.x().start + 0.5) / stride);
-            int64_t cy = (double((double)r.y().start + 0.5) / stride);
+            auto cx = sign_cast<uint64_t>((double((double)r.x().start + 0.5) / stride));
+            auto cy = sign_cast<uint64_t>((double((double)r.y().start + 0.5) / stride));
             
             size_t i = cy * N + cx;
             _array_grid.at(i) += r.size();
@@ -204,8 +204,8 @@ void HeatmapController::sort_data_into_custom_grid() {
             if(r.pixel_size() > uniform_grid_cell_size)
                 return true;
             
-            int64_t cx = (double((double)r.x().start + 0.5) / stride);
-            int64_t cy = (double((double)r.y().start + 0.5) / stride);
+            auto cx = sign_cast<uint64_t>((double((double)r.x().start + 0.5) / stride));
+            auto cy = sign_cast<uint64_t>((double((double)r.y().start + 0.5) / stride));
             
             size_t i = cy * N + cx;
             
@@ -232,8 +232,8 @@ void HeatmapController::sort_data_into_custom_grid() {
             values.reserve(_grid.size());
         
         _grid.apply<Leaf>([&](const Leaf& leaf) -> bool {
-            int64_t cx = (double((double)leaf.x().start + 0.5) / double(stride));
-            int64_t cy = (double((double)leaf.y().start + 0.5) / double(stride));
+            auto cx = sign_cast<uint64_t>((double((double)leaf.x().start + 0.5) / double(stride)));
+            auto cy = sign_cast<uint64_t>((double((double)leaf.y().start + 0.5) / double(stride)));
             
             size_t i = cy * N + cx;
             assert((size_t)i < _array_grid.size());
@@ -334,8 +334,8 @@ void HeatmapController::sort_data_into_custom_grid() {
     else
         mat.setTo(empty);
     
-    double percentage;
-    double ML = maximum - minimum;
+    Float2_t percentage;
+    auto ML = maximum - minimum;
     if(ML == 0)
         ML = 1;
     
@@ -346,7 +346,7 @@ void HeatmapController::sort_data_into_custom_grid() {
                 percentage = (_array_grid[i] / _array_samples[i] - minimum) / ML;
                 if(_normalization == normalization_t::variance)
                     percentage = 1 - percentage;
-                mat.at<cv::Vec4b>(y, x) = Viridis::value(percentage).alpha(percentage * 200);
+                mat.at<cv::Vec4b>(y, x) = Viridis::value(percentage).alpha(uint8_t(percentage * 200));
             }
         }
     }
diff --git a/Application/src/tracker/gui/gui.cpp b/Application/src/tracker/gui/gui.cpp
index 8dcbfcfc290f57fcd139adc1a555f7ceaac1ff56..4ca431cb3305567febd6d71134ea577ca3692176 100644
--- a/Application/src/tracker/gui/gui.cpp
+++ b/Application/src/tracker/gui/gui.cpp
@@ -884,7 +884,7 @@ void GUI::start_recording() {
         size_t max_number = 0;
         try {
             for(auto &file : frames.find_files()) {
-                auto name = file.filename().to_string();
+                auto name = std::string(file.filename());
                 if(utils::beginsWith(name, "clip")) {
                     try {
                         if(utils::endsWith(name, ".avi"))
@@ -982,7 +982,7 @@ void GUI::stop_recording() {
         }
         
     } else {
-        auto clip_name = _recording_path.filename().to_string();
+        auto clip_name = std::string(_recording_path.filename());
         printf("ffmpeg -start_number %d -i %s/%%06d.%s -vcodec libx264 -crf 13 -vf 'scale=trunc(iw/2)*2:trunc(ih/2)*2' -profile:v main -pix_fmt yuv420p %s.mp4\n", _recording_start, _recording_path.str().c_str(), _recording_format.name(), clip_name.c_str());
     }
     
@@ -1000,7 +1000,7 @@ std::string GUI::window_title() const {
     auto output_prefix = SETTING(output_prefix).value<std::string>();
     return SETTING(app_name).value<std::string>()
         + (SETTING(version).value<std::string>().empty() ? "" : (" " + SETTING(version).value<std::string>()))
-        + " (" + SETTING(filename).value<file::Path>().filename().to_string() + ")"
+        + " (" + (std::string)SETTING(filename).value<file::Path>().filename() + ")"
         + (output_prefix.empty() ? "" : (" ["+output_prefix+"]"));
 }
 
@@ -2514,7 +2514,7 @@ void GUI::selected_setting(long_t index, const std::string& name, Textfield& tex
                 auto && [unique, unique_map, up] = Accumulation::calculate_uniqueness(false, images, map);
                 auto coverage = data->draw_coverage(unique_map);
                 
-                auto path = pv::DataLocation::parse("output", "uniqueness"+video_source()->filename().filename().to_string()+".png");
+                auto path = pv::DataLocation::parse("output", "uniqueness"+(std::string)video_source()->filename().filename()+".png");
                 
                 Debug("Uniqueness: %f (output to '%S')", unique, &path.str());
                 cv::imwrite(path.str(), coverage->get());
@@ -4378,7 +4378,7 @@ void GUI::save_state(GUI::GUIType type, bool force_overwrite) {
                             if(file->remove_filename().empty()) {
                                 *file = file::Path("backup_" + file->str());
                             } else
-                                *file = file->remove_filename() / ("backup_" + file->filename().to_string());
+                                *file = file->remove_filename() / ("backup_" + (std::string)file->filename());
                         } while(file->exists());
                         
                         auto expected = Output::TrackingResults::expected_filename();
@@ -4577,7 +4577,7 @@ void GUI::save_visual_fields() {
     if(!fishdata.exists())
         if(!fishdata.create_folder())
             U_EXCEPTION("Cannot create folder '%S' for saving fishdata.", &fishdata.str());
-    auto filename = SETTING(filename).value<file::Path>().filename().to_string();
+    auto filename = (std::string)SETTING(filename).value<file::Path>().filename();
     
     if(selected) {
         auto path = fishdata / (filename + "_visual_field_"+selected->identity().name());
@@ -4661,7 +4661,7 @@ void GUI::export_tracks(const file::Path& , long_t fdx, Rangel range) {
 }
 
 file::Path GUI::frame_output_dir() const {
-    return pv::DataLocation::parse("output", file::Path("frames") / SETTING(filename).value<file::Path>().filename().to_string());
+    return pv::DataLocation::parse("output", file::Path("frames") / (std::string)SETTING(filename).value<file::Path>().filename());
 }
 
 std::string GUI::info(bool escape) {
diff --git a/Application/src/tracker/main.cpp b/Application/src/tracker/main.cpp
index 212506034af5667aa123bea221f6368ca10ddd4c..33ec9d3624f7a32c1cb285ce15f19371804305f9 100644
--- a/Application/src/tracker/main.cpp
+++ b/Application/src/tracker/main.cpp
@@ -356,7 +356,7 @@ int main(int argc, char** argv)
                                 continue;
                             
                             Debug("Found file '%S'", &file.str());
-                            auto filename = file.filename().to_string();
+                            auto filename = (std::string)file.filename();
                             
                             bool all_contained = true;
                             size_t offset = 0;
@@ -778,9 +778,9 @@ int main(int argc, char** argv)
         std::vector<Median<long_t>> medians;
         medians.resize(values.size());
         
-        int start_threshold = 5;
-        int end_threshold = 230;
-        float threshold_step = (end_threshold - 20 - start_threshold) / float(values.size());
+        float start_threshold = 5;
+        float end_threshold = 230;
+        float threshold_step = (end_threshold - 20 - start_threshold) / narrow_cast<float>(values.size());
         
         GenericThreadPool pool(cmn::hardware_concurrency());
         std::mutex sync;
@@ -796,17 +796,18 @@ int main(int argc, char** argv)
                 video.read_frame(frame, i);
             //video.read_frame(next_frame, i+1);
             
-                for(int threshold = start_threshold, j = 0; threshold <= end_threshold; threshold += threshold_step, ++j)
+                size_t j = 0;
+                for(float threshold = start_threshold; threshold <= end_threshold; threshold += threshold_step, ++j)
                 {
                     
                     float pixel_average = 0, pixel_samples = 0;
                     float number = 0;
                     
-                    for (int k=0; k<frame.n(); ++k) {
+                    for (uint16_t k=0; k<frame.n(); ++k) {
                         if(frame.pixels().at(k)->size() > 30) {
                             // consider blob
                             auto blob = std::make_shared<pv::Blob>(frame.mask().at(k), frame.pixels().at(k));
-                            auto blobs = pixel::threshold_blob(blob, threshold, Tracker::instance()->background());
+                            auto blobs = pixel::threshold_blob(blob, narrow_cast<int>(threshold), Tracker::instance()->background());
                             float pixels = 0, samps = 0;
                             
                             for(auto &b : blobs) {
@@ -833,7 +834,7 @@ int main(int argc, char** argv)
                         values.at(j).y += pixel_average;
                         values.at(j).x = j;
                         numbers[j] += number / pixel_samples;
-                        medians.at(j).addNumber(number);
+                        medians.at(j).addNumber(narrow_cast<int>(number));
                     }
                 }
                 
@@ -862,8 +863,8 @@ int main(int argc, char** argv)
         graph.set_ranges(Rangef(0, 255), Rangef(0, 1));
         graph.add_function(gui::Graph::Function("sizes", gui::Graph::Type::DISCRETE, [&, max_val = max_value](float x) -> float {
             auto threshold = (x - start_threshold) / threshold_step;
-            if(threshold >= 0 && threshold < values.size()) {
-                return values.at(threshold).y / max_val;
+            if(size_t(threshold) < values.size()) {
+                return values.at(size_t(threshold)).y / max_val;
             }
             return infinity<float>();
         }));
@@ -879,8 +880,8 @@ int main(int argc, char** argv)
         
         graph.add_function(gui::Graph::Function("samples", gui::Graph::Type::DISCRETE, [&, max_val = max_value](float x) -> float {
             auto threshold = (x - start_threshold) / float(end_threshold - start_threshold) * numbers.size();
-            if(threshold >= 0 && threshold < numbers.size()) {
-                return numbers.at(threshold) / max_val;
+            if(size_t(threshold) < numbers.size()) {
+                return numbers.at(size_t(threshold)) / max_val;
             }
             return infinity<float>();
         }));
@@ -893,15 +894,16 @@ int main(int argc, char** argv)
         
         graph.add_function(gui::Graph::Function("median_number", gui::Graph::Type::DISCRETE, [&, max_val = max_value](float x) -> float {
             auto threshold = (x - start_threshold) / float(end_threshold - start_threshold) * numbers.size();
-            if(threshold >= 0 && threshold < numbers.size()) {
-                return medians.at(threshold).getValue() / max_val;
+            if(size_t(threshold) < numbers.size()) {
+                return medians.at(size_t(threshold)).getValue() / max_val;
             }
             return infinity<float>();
         }));
         
-        for(int threshold = start_threshold, j = 0; threshold <= end_threshold && j < (int)values.size(); threshold += threshold_step, ++j)
+        size_t j=0;
+        for(auto threshold = start_threshold; threshold <= end_threshold && j < values.size(); threshold += threshold_step, ++j)
         {
-            printf("%d : %f (%d), %f\n", threshold, numbers.at(j), medians.at(j).getValue(), values.at(j).y);
+            printf("%f : %f (%d), %f\n", threshold, numbers.at(j), medians.at(j).getValue(), values.at(j).y);
         }
         printf("\n");
         
@@ -1023,7 +1025,7 @@ int main(int argc, char** argv)
             ptr->frame().set_index(idx);
             Tracker::preprocess_frame(*ptr, {}, pool.num_threads() > 1 ? &pool : NULL, NULL, false);
 
-            ptr->frame().set_loading_time(timer.elapsed());
+            ptr->frame().set_loading_time(narrow_cast<float>(timer.elapsed()));
 
             return true;
         },
@@ -1110,7 +1112,7 @@ int main(int argc, char** argv)
                         //Debug("frame %lu/%lu (%.2fMB/s @ %.2ffps)", ptr->index(), video.length(), data_sec / 1024.0, frames_sec);
                     }
 
-                    gui.frameinfo().current_fps = frames_sec;
+                    gui.frameinfo().current_fps = narrow_cast<int>(frames_sec);
                 }
 
                 frames_count++;
diff --git a/Application/src/tracker/misc/ConnectedTasks.cpp b/Application/src/tracker/misc/ConnectedTasks.cpp
index 5458f24a44db9e9bdd15ff24e60f4bcb125c4103..8aae8143b6b9b0d76796aff3f11a7b28893762e2 100644
--- a/Application/src/tracker/misc/ConnectedTasks.cpp
+++ b/Application/src/tracker/misc/ConnectedTasks.cpp
@@ -46,7 +46,7 @@ namespace cmn {
                         _finish_condition.notify_one();
                         
                         if(result) {
-                            stage.timings += stage.timer.elapsed();
+                            stage.timings += (float)stage.timer.elapsed();
                             stage.samples ++;
                             stage.average_time = stage.timings / stage.samples;
                         }
diff --git a/Application/src/tracker/misc/Output.cpp b/Application/src/tracker/misc/Output.cpp
index a6631223f0e5674a0f02667530b0511cac8999ac..1a7b366c36133db6d309b34018d970e30dd5a77e 100644
--- a/Application/src/tracker/misc/Output.cpp
+++ b/Application/src/tracker/misc/Output.cpp
@@ -212,8 +212,18 @@ void Output::ResultsFormat::read_blob(Data& ref, pv::CompressedBlob& blob) const
     ref.read<uint16_t>(start_y);
     ref.read<uint16_t>(len);
     
-    blob.lines.resize(len);
-    ref.read_data(elem_size * len, (char*)blob.lines.data());
+    if(_header.version < Output::ResultsFormat::Versions::V_32) {
+        std::vector<pv::LegacyShortHorizontalLine> legacy(len);
+        blob.lines.clear();
+        blob.lines.reserve(len);
+        
+        ref.read_data(sizeof(pv::LegacyShortHorizontalLine) * len, (char*)legacy.data());
+        std::copy(legacy.begin(), legacy.end(), std::back_inserter(blob.lines));
+        
+    } else {
+        blob.lines.resize(len);
+        ref.read_data(elem_size * len, (char*)blob.lines.data());
+    }
     
     blob.status_byte = byte;
     blob.start_y = start_y;
@@ -311,7 +321,7 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi
         ID = (uint32_t)sid;
     }
     
-    Individual *fish = new Individual(ID);
+    Individual *fish = new Individual(narrow_cast<long_t>(ID));
     
     if(_header.version <= Output::ResultsFormat::Versions::V_15) {
         ref.seek(ref.tell() + sizeof(data_long_t) * 2);
@@ -330,10 +340,10 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi
         std::string name;
         ref.read<std::string>(name);
         
-        Identity id(ID);
+        Identity id((long_t)ID);
         if(name != id.raw_name() && !name.empty()) {
             auto map = FAST_SETTINGS(individual_names);
-            map[ID] = name;
+            map[(long_t)ID] = name;
             SETTING(individual_names) = map;
         }
     }
@@ -350,7 +360,7 @@ Individual* Output::ResultsFormat::read_individual(cmn::Data &ref, const CacheHi
         }
     }
     
-    fish->identity().set_ID(ID);
+    fish->identity().set_ID((long_t)ID);
     
     //PhysicalProperties *prev = NULL;
     //PhysicalProperties *prev_weighted = NULL;
@@ -669,7 +679,7 @@ template<> void Data::read(Individual*& out_ptr) {
             double N_written = results->_N_written.load();
             if(N <= 100 || results->_N_written % max(100u, uint64_t(N * 0.01)) == 0) {
                 Debug("Read individual %.0f/%lu (%.0f%%)...", N_written, N, N_written / float(N) * 100);
-                results->_update_progress("", N_written / float(N), results->filename().str()+"\n<ref>loading individual</ref> <number>"+Meta::toStr(results->_N_written)+"</number> <ref>of</ref> <number>"+Meta::toStr(N)+"</number>");
+                results->_update_progress("", narrow_cast<float>(N_written / double(N)), results->filename().str()+"\n<ref>loading individual</ref> <number>"+Meta::toStr(results->_N_written)+"</number> <ref>of</ref> <number>"+Meta::toStr(N)+"</number>");
             }
         }
     });
@@ -749,7 +759,7 @@ uint64_t Data::write(const Individual& val) {
         pos += ptr->current_offset();
         
         if(pos - ptr->last_callback > ptr->estimated_size * 0.01) {
-            ptr->_update_progress("", min(1, double(pos)/double(ptr->estimated_size)), "");
+            ptr->_update_progress("", narrow_cast<float>(min(1.0, double(pos)/double(ptr->estimated_size))), "");
             ptr->last_callback = pos;
         }
     };
@@ -946,13 +956,13 @@ namespace Output {
                 read<uint32_t>(start);
                 read<uint32_t>(end);
                 
-                _header.consecutive_segments.push_back(Rangel(start, end));
+                _header.consecutive_segments.push_back(Rangel(narrow_cast<long_t>(start), narrow_cast<long_t>(end)));
             }
             
             read<Size2>(_header.video_resolution);
             read<uint64_t>(_header.video_length);
             
-            _header.average.create(_header.video_resolution.height, _header.video_resolution.width, 1);
+            _header.average.create((uint)_header.video_resolution.height, (uint)_header.video_resolution.width, 1);
             read_data(_header.average.size(), (char*)_header.average.data());
         }
         
@@ -989,8 +999,8 @@ namespace Output {
         auto consecutive = Tracker::instance()->consecutive();
         write<uint32_t>((uint32_t)consecutive.size());
         for (auto &c : consecutive) {
-            write<uint32_t>(c.start);
-            write<uint32_t>(c.end);
+            write<uint32_t>(sign_cast<uint32_t>(c.start));
+            write<uint32_t>(sign_cast<uint32_t>(c.end));
         }
         
         write<Size2>(Tracker::average().bounds().size());
@@ -1006,7 +1016,7 @@ namespace Output {
     
     uint64_t ResultsFormat::write_data(uint64_t num_bytes, const char *buffer) {
         if(current_offset() - last_callback > estimated_size * 0.01) {
-            _update_progress("", min(1, double(current_offset()+num_bytes)/double(estimated_size)), "");
+            _update_progress("", narrow_cast<float>(min(1.0, double(current_offset()+num_bytes)/double(estimated_size))), "");
             last_callback = current_offset();
         }
         
@@ -1084,8 +1094,8 @@ namespace Output {
     }
     
     Path TrackingResults::expected_filename() {        
-        file::Path filename = SETTING(filename).value<Path>().filename().to_string();
-        filename = filename.extension().to_string() == "pv" ?
+        file::Path filename = SETTING(filename).value<Path>().filename();
+        filename = filename.extension() == "pv" ?
         filename.replace_extension("results") : filename.add_extension("results");
         return pv::DataLocation::parse("output", filename);
     }
@@ -1102,7 +1112,7 @@ namespace Output {
         filename = filename.add_extension("tmp01");
         
         ResultsFormat file(filename.str(), update_progress);
-        file.header().gui_frame = SETTING(gui_frame).value<long_t>();
+        file.header().gui_frame = sign_cast<uint64_t>(SETTING(gui_frame).value<long_t>());
         file.start_writing(true);
         file.write_file(_tracker._added_frames, _tracker._active_individuals_frame, _tracker._individuals, exclude_settings);
         file.close();
@@ -1180,7 +1190,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f
         prev_props = &props;
         prev_frame = props.frame;
         
-        if(props.frame % max(1u, uint64_t(_tracker._added_frames.size() * 0.1)) == 0) {
+        if((uint)props.frame % max(1u, uint64_t(_tracker._added_frames.size() / 10u)) == 0) {
             update_progress("FOIs...", props.frame / float(_tracker.end_frame()), Meta::toStr(props.frame)+" / "+Meta::toStr(_tracker.end_frame()));
             if(!SETTING(quiet))
                 Debug("\tupdate_fois %d / %d\r", props.frame, _tracker.end_frame());
@@ -1203,7 +1213,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f
 
         if(!filename.exists()) {
             file::Path file = SETTING(filename).value<Path>();
-            file = file.extension().to_string() == "pv" ?
+            file = file.extension() == "pv" ?
             file.replace_extension("results") : file.add_extension("results");
             
             //file = pv::DataLocation::parse("input", filename.filename());
@@ -1331,7 +1341,7 @@ void TrackingResults::update_fois(const std::function<void(const std::string&, f
             }
         }
         
-        track::Identity::set_running_id(uint32_t(biggest_id+1));
+        track::Identity::set_running_id(biggest_id+1);
         
         uint64_t n;
         data_long_t ID;
diff --git a/Application/src/tracker/misc/Output.h b/Application/src/tracker/misc/Output.h
index 35b3b4f6312f42ad3fc29aa3bf5cce40bf69d715..4a33e9277bb7380c2de58b472387bed2b7386d3b 100644
--- a/Application/src/tracker/misc/Output.h
+++ b/Application/src/tracker/misc/Output.h
@@ -109,8 +109,9 @@ namespace Output {
             V_29, // removing Vec2 from individuals for centroid position
             V_30, // add analysis_range information to header
             V_31, // add number of individuals per frame
+            V_32, // change ShortHorizontalLine format
             
-            current = V_31
+            current = V_32
         };
         
     private:
diff --git a/Application/src/tracker/misc/default_config.cpp b/Application/src/tracker/misc/default_config.cpp
index 088e3d6d1b11968737b9af66e83cafe09c597562..ac07cf1515455e59a0008980304417ff3689a578 100644
--- a/Application/src/tracker/misc/default_config.cpp
+++ b/Application/src/tracker/misc/default_config.cpp
@@ -684,11 +684,11 @@ file::Path conda_environment_path() {
                 path = SETTING(settings_file).value<Path>();
             if(path.empty()) {
                 path = SETTING(filename).value<Path>();
-                if(path.has_extension() && path.extension().to_string() == "pv")
+                if(path.has_extension() && path.extension() == "pv")
                     path = path.remove_extension();
             }
             
-            if(!path.has_extension() || path.extension().to_string() != "settings")
+            if(!path.has_extension() || path.extension() != "settings")
                 path = path.add_extension("settings");
             
             auto settings_file = pv::DataLocation::parse("input", path);
@@ -699,11 +699,11 @@ file::Path conda_environment_path() {
         });
         
         pv::DataLocation::register_path("output_settings", [](file::Path) -> file::Path {
-            file::Path settings_file = SETTING(filename).value<Path>().filename().to_string();
+            file::Path settings_file = SETTING(filename).value<Path>().filename();
             if(settings_file.empty())
                 U_EXCEPTION("settings_file is an empty string.");
             
-            if(!settings_file.has_extension() || settings_file.extension().to_string() != "settings")
+            if(!settings_file.has_extension() || settings_file.extension() != "settings")
                 settings_file = settings_file.add_extension("settings");
             
             return pv::DataLocation::parse("output", settings_file);
diff --git a/Application/src/tracker/tracking/Accumulation.cpp b/Application/src/tracker/tracking/Accumulation.cpp
index c3dfcd4e29abb07722049a0532ad9e956df3a089..97be1f5c34a0ebd3352e3ee34c0e49b701120b4e 100644
--- a/Application/src/tracker/tracking/Accumulation.cpp
+++ b/Application/src/tracker/tracking/Accumulation.cpp
@@ -385,7 +385,7 @@ void Accumulation::update_coverage(const TrainingData &data) {
         cv::Mat copy;
         cv::cvtColor(image->get(), copy, cv::COLOR_BGRA2RGBA);
         
-        auto image_path = pv::DataLocation::parse("output", "coverage_"+SETTING(filename).value<file::Path>().filename().to_string()+"_a"+Meta::toStr(_accumulation_step)+"_e"+Meta::toStr(_counted_steps)+".png");
+        auto image_path = pv::DataLocation::parse("output", "coverage_"+SETTING(filename).value<file::Path>().filename()+"_a"+Meta::toStr(_accumulation_step)+"_e"+Meta::toStr(_counted_steps)+".png");
         _coverage_paths.push_back(image_path);
         cv::imwrite(image_path.str(), copy);
         //tf::imshow("coverage", copy);
@@ -764,7 +764,7 @@ bool Accumulation::start() {
         if(SETTING(recognition_save_training_images)) {
             try {
                 auto data = _collected_data->join_split_data();
-                auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename().to_string()+"_validation_data.npz"));
+                auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename()+"_validation_data.npz"));
                 
                 const Size2 dims = SETTING(recognition_image_size);
                 FileSize size((data.validation_images.size() + data.training_images.size()) * dims.width * dims.height);
@@ -1330,7 +1330,7 @@ bool Accumulation::start() {
     // save validation data
     try {
         auto data = _collected_data->join_split_data();
-        auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename().to_string()+"_validation_data.npz"));
+        auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename()+"_validation_data.npz"));
         
         const Size2 dims = SETTING(recognition_image_size);
         FileSize size((data.validation_images.size() + data.training_images.size()) * dims.width * dims.height);
@@ -1488,7 +1488,7 @@ bool Accumulation::start() {
                             ? std::unordered_set<Individual*>()
                             : Tracker::active_individuals(frame-1);
                     
-                    video_file.read_frame(video_frame.frame(), frame);
+                    video_file.read_frame(video_frame.frame(), sign_cast<uint64_t>(frame));
                     Tracker::instance()->preprocess_frame(video_frame, active, NULL);
                     
                     std::map<uint32_t, pv::BlobPtr> blob_to_id;
@@ -1511,8 +1511,8 @@ bool Accumulation::start() {
                         if(bidx == -1 || pidx == -1)
                             continue;
                         
-                        auto &basic = fish->basic_stuff()[bidx];
-                        auto posture = pidx != -1 ? fish->posture_stuff()[pidx] : nullptr;
+                        auto &basic = fish->basic_stuff()[size_t(bidx)];
+                        auto posture = pidx > -1 ? fish->posture_stuff()[size_t(pidx)] : nullptr;
 
                         auto bid = basic->blob.blob_id();
                         auto pid = basic->blob.parent_id;
@@ -1555,7 +1555,7 @@ bool Accumulation::start() {
                 // save validation data
                 try {
                     //auto data = _collected_data->join_split_data();
-                    auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename().to_string()+"_validation_data_"+method.name()+".npz"));
+                    auto ranges_path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename()+"_validation_data_"+method.name()+".npz"));
                     
                     
                     const Size2 dims = SETTING(recognition_image_size);
@@ -1566,7 +1566,7 @@ bool Accumulation::start() {
                         total_images+=img.size();
                     }
                     
-                    FileSize size(total_images * dims.width * dims.height);
+                    FileSize size(uint64_t(total_images * dims.width * dims.height));
                     auto ss = size.to_string();
                     Debug("Images are %S big. Saving to '%S'.", &ss, &ranges_path.str());
                     
@@ -1596,7 +1596,7 @@ bool Accumulation::start() {
         size_t gpu_max_epochs = SETTING(gpu_max_epochs);
         float acc = best_uniqueness();
         current_best = 0;
-        Recognition::train(_collected_data, FrameRange(), TrainingMode::Accumulate, max(3, gpu_max_epochs * 0.25), true, &acc, -2);
+        Recognition::train(_collected_data, FrameRange(), TrainingMode::Accumulate, narrow_cast<int>(max(3.f, gpu_max_epochs * 0.25f)), true, &acc, -2);
         
         if(acc >= best_uniqueness()) {
             {
@@ -1625,7 +1625,7 @@ bool Accumulation::start() {
     }
     
     try {
-        auto path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename().to_string()+"_range_history.npz"));
+        auto path = pv::DataLocation::parse("output", Path(SETTING(filename).value<file::Path>().filename()+"_range_history.npz"));
         npz_save(path.str(), "tried_ranges", _checked_ranges_output.data(), {_checked_ranges_output.size() / 2, 2});
         Debug("[Accumulation STOP] Saved range history to '%S'.", &path.str());
         
@@ -1643,7 +1643,7 @@ bool Accumulation::start() {
 }
 
 float Accumulation::accepted_uniqueness(float base) const {
-    return (base == -1 ? best_uniqueness() : base) * 0.98;
+    return (base == -1 ? best_uniqueness() : base) * 0.98f;
 }
 
 void Accumulation::end_a_step(Result reason) {
@@ -1813,7 +1813,7 @@ void Accumulation::update_display(gui::Entangled &e, const std::string& text) {
             Vec2 offset;
             float previous = accepted_uniqueness();
             size_t i=0;
-            const Font font(0.6, Align::Center);
+            const Font font(0.6f, Align::Center);
             
             for(auto &d : history) {
                 if(long_t(i) < long_t(history.size()) - 10) {
diff --git a/Application/src/tracker/tracking/Export.cpp b/Application/src/tracker/tracking/Export.cpp
index 72dc30499db7f36f76f97da87de622942345c17c..1adab065be3d69228a7e76e839637617b575d8c6 100644
--- a/Application/src/tracker/tracking/Export.cpp
+++ b/Application/src/tracker/tracking/Export.cpp
@@ -38,21 +38,21 @@ namespace hist_utils {
         assert(img.rows == med.rows);
         assert(img.cols == med.cols);
         
-        for (int r = 0; r < img.rows; ++r) {
-            for (int c = 0; c < img.cols; ++c){
+        for (uint r = 0; r < (uint)img.rows; ++r) {
+            for (uint c = 0; c < (uint)img.cols; ++c){
                 
                 // Add pixel to histogram
                 Hist& hist = M[r][c];
-                ++hist.h[img(r, c)];
+                ++hist.h[img((int)r, (int)c)];
                 ++hist.count;
                 
                 // Compute median
-                int i;
+                uint i;
                 int n = hist.count / 2;
                 for (i = 0; i < 256 && ((n -= hist.h[i]) >= 0); ++i);
                 
                 // 'i' is the median value
-                med(r,c) = uchar(i);
+                med((int)r,(int)c) = uchar(i);
             }
         }
         
@@ -91,9 +91,9 @@ namespace hist_utils {
     {
         med = Mat1b(rows, cols, uchar(0));
         M.clear();
-        M.resize(rows);
-        for (int i = 0; i < rows; ++i) {
-            M[i].resize(cols);
+        M.resize((uint)rows);
+        for (uint i = 0; i < (uint)rows; ++i) {
+            M[i].resize((uint)cols);
         }
     }
 }
@@ -137,7 +137,7 @@ Float2_t polygonArea(const std::vector<Vec2>& pts)
     }
     
     // Return absolute value
-    return cmn::abs(area / 2.0);
+    return cmn::abs(area / 2.0f);
 }
 
 void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
@@ -182,7 +182,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
         if(!fishdata.create_folder())
             U_EXCEPTION("Cannot create folder '%S' for saving fishdata.", &fishdata.str());
     
-    auto filename = SETTING(filename).value<file::Path>().filename().to_string();
+    auto filename = std::string(SETTING(filename).value<file::Path>().filename());
     auto posture_path = (fishdata / (filename + "_posture_*.npz")).str();
     auto recognition_path = (fishdata / (filename + "_recognition_*.npz")).str();
     
@@ -233,7 +233,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                    // added_frames += counter % print_step_size;
                     
                     if(GUI::instance()) {
-                        GUI::instance()->work().set_percent(overall_percent / all_percents.size() * (output_posture_data ? 0.5 : 1.0));
+                        GUI::instance()->work().set_percent(overall_percent / all_percents.size() * (output_posture_data ? 0.5f : 1.0f));
                         overall_percent = GUI::instance()->work().percent();
                     }
                 }
@@ -266,7 +266,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     else
                         fish_graphs.at(thread_index)->setup_graph(fish->start_frame(), Rangel(fish->start_frame(), fish->end_frame()), fish, library_cache.at(thread_index));
                     
-                    file::Path path = (SETTING(filename).value<file::Path>().filename().to_string() + "_" + fish->identity().name() + "." + output_format.name());
+                    file::Path path = ((std::string)SETTING(filename).value<file::Path>().filename() + "_" + fish->identity().name() + "." + output_format.name());
                     
                     /**
                      * There is sometimes a problem when people save to network harddrives.
@@ -295,8 +295,13 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                                 segment_borders.push_back(segment->start());
                                 segment_borders.push_back(segment->end());
                                 
-                                for(long_t frame = segment->start() + 1; frame <= segment->end(); ++frame) {
-                                    auto centroid = fish->basic_stuff()[segment->basic_stuff(frame)]->centroid;
+                                for(long_t frame = segment->start() + 1; frame <= segment->end(); ++frame)
+                                {
+                                    auto idx = segment->basic_stuff(frame);
+                                    if(idx < 0)
+                                        continue;
+                                    
+                                    auto centroid = fish->basic_stuff()[(size_t)idx]->centroid;
                                     
                                     auto v = centroid->v(Units::PX_AND_SECONDS);
                                     auto speed = centroid->speed(Units::PX_AND_SECONDS);
@@ -367,11 +372,11 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                                         assert(blob);
                                         
                                         auto trans = midline->transform(normalize);
-                                        long_t org_id = -1;
+                                        int64_t org_id = -1;
                                         
                                         if(SETTING(tracklet_restore_split_blobs) && blob->parent_id() != -1) {
                                             pv::Frame pvf;
-                                            GUI::instance()->video_source()->read_frame(pvf, frame);
+                                            GUI::instance()->video_source()->read_frame(pvf, (uint64_t)frame);
                                             auto bs = pvf.get_blobs();
                                             //Debug("Blob %d in frame %d has been split (%d)", blob->blob_id(), frame, blob->parent_id());
                                             
@@ -380,7 +385,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                                                     //Debug("Replacing blob %d with parent blob %d", blob->blob_id(), b->blob_id());
                                                     b->calculate_moments();
                                                     trans.translate(-(blob->bounds().pos() - b->bounds().pos()));
-                                                    org_id = blob->blob_id();
+                                                    org_id = (int64_t)blob->blob_id();
                                                     blob = b;
                                                     break;
                                                 }
@@ -404,14 +409,14 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                 
                 if(recognition_enable && SETTING(output_recognition_data)) {
                     // output network data
-                    file::Path path = (SETTING(filename).value<file::Path>().filename().to_string() + "_recognition_" + fish->identity().name() + ".npz");
+                    file::Path path = ((std::string)SETTING(filename).value<file::Path>().filename() + "_recognition_" + fish->identity().name() + ".npz");
                     
                     Rangel fish_range(range);
                     if(range.empty())
                         fish_range = Rangel(fish->start_frame(), fish->end_frame());
                     
                     std::vector<float> probabilities;
-                    probabilities.reserve(fish_range.length() * Recognition::number_classes());
+                    probabilities.reserve((size_t)fish_range.length() * Recognition::number_classes());
                     
                     std::vector<long_t> recognition_frames;
                     
@@ -452,7 +457,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                 }
                 
                 if(output_posture_data) {
-                    file::Path path = (SETTING(filename).value<file::Path>().filename().to_string() + "_posture_" + fish->identity().name() + ".npz");
+                    file::Path path = ((std::string)SETTING(filename).value<file::Path>().filename() + "_posture_" + fish->identity().name() + ".npz");
                     
                     Rangel fish_range(range);
                     if(range.empty())
@@ -463,11 +468,11 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     std::vector<Vec2> midline_points, outline_points, midline_points_raw;
                     std::vector<Vec2> offsets;
                     std::vector<float> midline_angles, midline_cms, areas, midline_offsets;
-                    midline_points.reserve(fish_range.length() * 2 * FAST_SETTINGS(midline_resolution));
+                    midline_points.reserve((size_t)fish_range.length() * 2 * FAST_SETTINGS(midline_resolution));
                     midline_points_raw.reserve(midline_points.capacity());
-                    midline_angles.reserve(fish_range.length());
-                    midline_offsets.reserve(fish_range.length());
-                    areas.reserve(fish_range.length());
+                    midline_angles.reserve((size_t)fish_range.length());
+                    midline_offsets.reserve((size_t)fish_range.length());
+                    areas.reserve((size_t)fish_range.length());
                     //outline_points.reserve(fish_range.length() * 2);
                     
                     size_t num_midline_points = 0, num_outline_points = 0;
@@ -477,7 +482,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     size_t first_midline_length = 0;
                     bool same_midline_length = true;
                     size_t counter = 0;
-                    size_t print_step_size = fish_range.length() * 0.01;
+                    size_t print_step_size = size_t(fish_range.length()) / 100u;
                     if(print_step_size == 0)
                         print_step_size = 1;
                     
@@ -633,7 +638,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
         
         if(SETTING(output_statistics))
         {
-            file::Path path = (SETTING(filename).value<file::Path>().filename().to_string() + "_statistics.npz");
+            file::Path path = ((std::string)SETTING(filename).value<file::Path>().filename() + "_statistics.npz");
             
             if(!(fishdata / path).exists() || Tracker::instance()->_statistics.size() == Tracker::number_frames())
             {
@@ -668,7 +673,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                 }
                 
                 if(!auto_no_memory_stats) {
-                    final_path = fishdata / (SETTING(filename).value<file::Path>().filename().to_string() + "_memory.npz");
+                    final_path = fishdata / ((std::string)SETTING(filename).value<file::Path>().filename() + "_memory.npz");
                     temporary_save(final_path, [&](file::Path path){
                         Debug("Generating memory stats...");
                         mem::IndividualMemoryStats overall;
@@ -705,7 +710,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                         Debug("Saved memory stats at '%S'", &final_path);
                     });
                     
-                    final_path = fishdata / (SETTING(filename).value<file::Path>().filename().to_string() + "_global_memory.npz");
+                    final_path = fishdata / ((std::string)SETTING(filename).value<file::Path>().filename() + "_global_memory.npz");
                     temporary_save(final_path, [&](file::Path path){
                         mem::OutputLibraryMemoryStats ol;
                         ol.print();
@@ -754,7 +759,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     static Timing timing("[tracklet_images] preprocess", 20);
                     TakeTiming take(timing);
                     auto active = frame == Tracker::start_frame() ? std::unordered_set<Individual*>() : Tracker::active_individuals(frame-1);
-                    GUI::instance()->video_source()->read_frame(obj.frame(), frame);
+                    GUI::instance()->video_source()->read_frame(obj.frame(), sign_cast<uint64_t>(frame));
                     Tracker::instance()->preprocess_frame(obj, active, &_blob_thread_pool);
                 }
                 
@@ -894,7 +899,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                                 cv::circle(image, -offset + reduced.blob->bounds().size() * 0.5, 5, gui::Red);
                                 cv::line(image, -offset + reduced.blob->bounds().size() * 0.5, -offset - center_offset + reduced.blob->bounds().size() * 0.5, gui::Yellow);
                                 
-                                cv::Mat empty_file = cv::Mat::zeros(output_size.height, output_size.width, CV_8UC3);
+                                cv::Mat empty_file = cv::Mat::zeros((int)output_size.height, (int)output_size.width, CV_8UC3);
                                 Bounds input_bounds(-center_offset, Size2(image) + center_offset);
                                 cv::putText(image, "input "+Meta::toStr(input_bounds), Vec2(20), cv::FONT_HERSHEY_PLAIN, 0.7, gui::White);
                                 
@@ -904,12 +909,12 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                                 input_bounds.pos() += (output_size - Size2(image)) * 0.5;
                                 input_bounds.size() = Size2(image);
                                 if(input_bounds.x < 0) {
-                                    left = -input_bounds.x;
+                                    left = -(int)input_bounds.x;
                                     input_bounds.x = 0;
                                     input_bounds.width -= left;
                                 }
                                 if(input_bounds.y < 0) {
-                                    top = -input_bounds.y;
+                                    top = -(int)input_bounds.y;
                                     input_bounds.height -= top;
                                     input_bounds.y = 0;
                                 }
@@ -988,23 +993,24 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
             };
             
             // output network data
-            file::Path path = fishdata / (SETTING(filename).value<file::Path>().filename().to_string() + "_tracklet_images.npz");
-            file::Path single_path = fishdata / (SETTING(filename).value<file::Path>().filename().to_string() + "_tracklet_images_single");
+            file::Path path = fishdata / ((std::string)SETTING(filename).value<file::Path>().filename() + "_tracklet_images.npz");
+            file::Path single_path = fishdata / ((std::string)SETTING(filename).value<file::Path>().filename() + "_tracklet_images_single");
             
             if(!split_masks.empty()) {
                 auto path = single_path.str() + "_splits_part";
                 Debug("Saving split tracklet masks to '%S'... (%d images)", &path, split_frames.size());
                 
-                size_t bytes_per_image = (size_t)output_size.height * (size_t)output_size.width;
-                size_t n_images = (1.5 *1000 * 1000 * 1000) / bytes_per_image;
+                int64_t bytes_per_image = (int64_t)output_size.height * (int64_t)output_size.width;
+                int64_t n_images = int64_t(1.5 *1000 * 1000 * 1000) / bytes_per_image;
                 
                 Debug("%d/%d images fit in 1.5GB", n_images, split_frames.size());
                 
-                size_t offset = 0;
+                int64_t offset = 0;
                 size_t part = 0;
+                int64_t N = narrow_cast<int64_t>(split_frames.size());
                 
-                while (offset < split_frames.size()) {
-                    auto L = min(n_images, split_frames.size() - offset);
+                while (offset < N) {
+                    auto L = min(n_images, N - offset);
                     
                     auto sub_path = path + Meta::toStr(part) + ".npz";
                     ++part;
@@ -1013,8 +1019,8 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     
                     temporary_save(sub_path, [&](file::Path path) {
                         cmn::npz_save(path.str(), "images",
-                                      split_masks.data() + offset * (size_t)output_size.height * (size_t)output_size.width,
-                                      { L, (size_t)output_size.height, (size_t)output_size.width }, "w");
+                                      split_masks.data() + offset * (int64_t)output_size.height * (int64_t)output_size.width,
+                                      { sign_cast<size_t>(L), (size_t)output_size.height, (size_t)output_size.width }, "w");
                         cmn::npz_save(path.str(), "frames", std::vector<long_t>(split_frames.begin() + offset, split_frames.begin() + offset + L), "a");
                         cmn::npz_save(path.str(), "ids", std::vector<long_t>(split_ids.begin() + offset, split_ids.begin() + offset + L), "a");
                     });
@@ -1038,7 +1044,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                 
                 for(auto && [range, images] : ranges) {
                     size_t image_count = 0;
-                    hist_utils::init(M, med, output_size.height, output_size.width);
+                    hist_utils::init(M, med, (int)output_size.height, (int)output_size.width);
                     
                     while(!images.empty()) {
                         auto [frame, fid, image] = images.front();
@@ -1078,7 +1084,7 @@ void export_data(Tracker& tracker, long_t fdx, const Rangel& range) {
                     Debug("[tracklet_images] Fish %d...", id);
             }
             
-            size_t samples = all_images.size() / output_size.height / output_size.width;
+            size_t samples = all_images.size() / (size_t)output_size.height / (size_t)output_size.width;
             Debug("Saving tracklet images to '%S'... (%d samples)", &path.str(), samples);
             
             temporary_save(path, [&](file::Path path){
diff --git a/Application/src/tracker/tracking/FOI.cpp b/Application/src/tracker/tracking/FOI.cpp
index 6bc7c0e18a77f1c309396c64dfc253aac1637d7f..82c56e39b7a33d5507c8b12370d5ae142a0102f5 100644
--- a/Application/src/tracker/tracking/FOI.cpp
+++ b/Application/src/tracker/tracking/FOI.cpp
@@ -187,7 +187,7 @@ bool FOI::operator==(const FOI& other) const {
     
     uint64_t FOI::last_change() {
         std::lock_guard<std::recursive_mutex> guard(_mutex);
-        return last_change_time.time_since_epoch().count();
+        return (uint64_t)last_change_time.time_since_epoch().count();
     }
     
     void FOI::changed() {
diff --git a/Application/src/tracker/tracking/Individual.h b/Application/src/tracker/tracking/Individual.h
index d4dc64f9c77b09bbe397d87cff2b4230acd0c7a3..54b1201e4aede83917e1fe5d83b3c92313d7ef2a 100644
--- a/Application/src/tracker/tracking/Individual.h
+++ b/Application/src/tracker/tracking/Individual.h
@@ -95,7 +95,7 @@ namespace track {
         std::map<idx_t, IndividualCache> cached_individuals;
         std::map<uint32_t, std::set<long_t>> blob_cliques, fish_cliques;
         std::set<uint32_t> split_blobs;
-        std::map<long_t, pv::BlobPtr> bdx_to_ptr;
+        std::map<uint32_t, pv::BlobPtr> bdx_to_ptr;
         grid::ProximityGrid blob_grid;
         
         PPFrame();
diff --git a/Application/src/tracker/tracking/Recognition.cpp b/Application/src/tracker/tracking/Recognition.cpp
index f998429dbd484d97c83a8a5072d26c5f4ad42e84..244b50849cf037cd996e0929defdd4d5ec5c8761 100644
--- a/Application/src/tracker/tracking/Recognition.cpp
+++ b/Application/src/tracker/tracking/Recognition.cpp
@@ -47,7 +47,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
     else if (normalize == default_config::recognition_normalization_t::moments)
     {
         gui::Transform tr;
-        float angle = -blob->orientation() + M_PI * 0.25;
+        float angle = narrow_cast<float>(-blob->orientation() + M_PI * 0.25);
         
         tr.rotate(DEGREE(angle));
         tr.translate( -blob->bounds().size() * 0.5);
@@ -69,7 +69,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
         std::transform(v.begin(), v.end(), diff.begin(), [mean](double x) { return x - mean; });
         double sq_sum = std::inner_product(diff.begin(), diff.end(), diff.begin(), 0.0);
         
-        return std::sqrt(sq_sum / v.size());
+        return (float)std::sqrt(sq_sum / v.size());
     }
     
     void Recognition::notify() {
@@ -581,7 +581,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
         size_t waiting_images = 0;
         
         const float cache_capacity_megabytes = SETTING(gpu_max_cache).value<float>() * 1000;
-        const float image_megabytes = output_shape.width * output_shape.height / 1000.0 / 1000.0;
+        const float image_megabytes = output_shape.width * output_shape.height / 1000.f / 1000.f;
         
         auto set_frame_for_fish = [this](fdx_t fdx, frame_t frame) {
             auto it = _fish_last_frame.find(fdx);
@@ -726,11 +726,11 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
         if (!python_available())
             return false;
         
-        auto running = set_running(true, "update_internal_training");
         
         // collect a number of images to analyse until a certain limit is reached
         // the limit can be in time or because of the number of fish
         std::shared_ptr<Tracker::LockGuard> tracker_guard = std::make_shared<Tracker::LockGuard>("update_internal_training");
+        auto running = set_running(true, "update_internal_training");
         std::unique_lock<decltype(_data_queue_mutex)> guard(_data_queue_mutex);
         std::map<long_t, std::map<uint32_t, ImageData>> waiting_for_pixels;
         
@@ -832,9 +832,12 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
                             if(index < 0)
                                 continue;
                             
-                            auto &posture = fish->posture_stuff().at(index);
+                            auto &posture = fish->posture_stuff().at((size_t)index);
                             auto bid = segment.basic_stuff(posture->frame);
-                            auto &basic = fish->basic_stuff().at(bid);
+                            if(bid < 0)
+                                continue;
+                            
+                            auto &basic = fish->basic_stuff().at((size_t)bid);
                             
                             if(!eligible_for_training(basic, posture, filters))
                                 continue;
@@ -847,7 +850,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
                             if(index < 0)
                                 continue;
                             
-                            auto &basic = fish->basic_stuff().at(index);
+                            auto &basic = fish->basic_stuff().at((size_t)index);
                             if(!eligible_for_training(basic, nullptr, filters))
                                 continue;
                             
@@ -914,7 +917,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
                         return false;
                     }
                     
-                    GUI::instance()->video_source()->read_frame(frame.frame(), i);
+                    GUI::instance()->video_source()->read_frame(frame.frame(), (uint64_t)i);
                     Tracker::instance()->preprocess_frame(frame, prev_active, &Tracker::instance()->thread_pool());
                 }
             }
@@ -944,6 +947,8 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
                 if(!blob) {
                     _detail.set_unavailable_blobs(_detail.unavailable_blobs() + 1);
                     _detail.failed_frame(e.frame, e.fdx);
+                    static size_t counter = 0;
+                    Debug("Blob cannot be found (%lu).", ++counter);
                     continue;
                 }
                 
@@ -973,6 +978,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
                 } else {
                     _detail.set_unavailable_blobs(_detail.unavailable_blobs() + 1);
                     _detail.failed_frame(e.frame, e.fdx);
+                    Debug("Image is nullptr");
                 }
                 
                 if(waiting.size() >= SETTING(gpu_min_elements).value<size_t>() && !_running) {
@@ -1015,7 +1021,7 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
             ++since_tick;
             
             if(timer.elapsed() >= 1) {
-                fps = since_tick / timer.elapsed();
+                fps = narrow_cast<float>(since_tick / timer.elapsed());
                 since_tick = 0;
                 timer.reset();
                 
@@ -1318,8 +1324,8 @@ std::unique_ptr<Image> Recognition::calculate_diff_image_with_settings(const def
 
                 {
                     std::lock_guard<std::mutex> guard(_mutex);
-                    for(size_t j=0; j<indexes.size(); ++j) {
-                        size_t i = indexes.at(j);
+                    for(int64_t j=0; j<(int64_t)indexes.size(); ++j) {
+                        size_t i = narrow_cast<size_t>(indexes.at((size_t)j));
                         probs[data[i].frame][data[i].blob.blob_id] = std::vector<float>(values.begin() + j * FAST_SETTINGS(track_max_individuals), values.begin() + (j + 1) * FAST_SETTINGS(track_max_individuals));
                     }
                 }
@@ -1396,8 +1402,8 @@ void Recognition::predict_chunk_internal(const std::vector<Image::Ptr> & data, s
         
         {
             std::lock_guard<std::mutex> guard(_mutex);
-            for(size_t j=0; j<indexes.size(); ++j) {
-                size_t i = start_index + indexes.at(j);
+            for(int64_t j=0; j<(int64_t)indexes.size(); ++j) {
+                size_t i = start_index + narrow_cast<size_t>(indexes.at((size_t)j));
                 probabilities[i] = std::vector<float>(values.begin() + j * FAST_SETTINGS(track_max_individuals), values.begin() + (j + 1) * FAST_SETTINGS(track_max_individuals));
             }
         }
@@ -1408,8 +1414,8 @@ void Recognition::predict_chunk_internal(const std::vector<Image::Ptr> & data, s
 }
     
     file::Path Recognition::network_path() {
-        file::Path filename = SETTING(filename).value<file::Path>().filename().to_string();
-        filename = filename.extension().to_string() == "pv"
+        file::Path filename = SETTING(filename).value<file::Path>().filename();
+        filename = filename.extension() == "pv"
                 ? filename.remove_extension()
                 : filename;
         filename = pv::DataLocation::parse("output", filename.str() + "_weights");
@@ -1444,7 +1450,7 @@ void Recognition::check_learning_module(bool force) {
     {
         auto result = PythonIntegration::check_module("learn_static");
         if(result || force || py::is_none("classes", "learn_static")) {
-            size_t N = FAST_SETTINGS(track_max_individuals) ? FAST_SETTINGS(track_max_individuals) : 1;
+            size_t N = FAST_SETTINGS(track_max_individuals) ? (size_t)FAST_SETTINGS(track_max_individuals) : 1u;
             std::vector<idx_t> ids;
             ids.resize(N);
             
@@ -1478,7 +1484,7 @@ void Recognition::check_learning_module(bool force) {
             
             py::set_variable("output_path", filename.str(), "learn_static");
             py::set_variable("output_prefix", SETTING(output_prefix).value<std::string>(), "learn_static");
-            py::set_variable("filename", SETTING(filename).value<file::Path>().filename().to_string(), "learn_static");
+            py::set_variable("filename", (std::string)SETTING(filename).value<file::Path>().filename(), "learn_static");
         }
         
         if(result || force || py::is_none("update_work_percent", "learn_static")) {
diff --git a/Application/src/tracker/tracking/Tracker.cpp b/Application/src/tracker/tracking/Tracker.cpp
index f269fed5b95d83f73de3e442f2ecd960d14a2c7f..755eca81fd94f04be4f8e509c2f5f4890204a072 100644
--- a/Application/src/tracker/tracking/Tracker.cpp
+++ b/Application/src/tracker/tracking/Tracker.cpp
@@ -58,7 +58,7 @@ namespace track {
     
     inline void analyse_posture_pack(long_t frameIndex, const std::vector<std::tuple<Individual*, std::shared_ptr<Individual::BasicStuff>>>& p) {
         Timer t;
-        float collected = 0;
+        double collected = 0;
         for(auto && [f, b] : p) {
             t.reset();
             f->save_posture(b, frameIndex);
@@ -66,7 +66,7 @@ namespace track {
         }
         
         std::lock_guard<std::mutex> guard(Tracker::instance()->_statistics_mutex);
-        Tracker::instance()->_statistics[frameIndex].combined_posture_seconds += collected;
+        Tracker::instance()->_statistics[frameIndex].combined_posture_seconds += narrow_cast<float>(collected);
     }
     
     //std::map<long_t, std::map<uint32_t, long_t>> automatically_assigned_blobs;
@@ -582,8 +582,8 @@ bool operator<(long_t frame, const FrameProperties& props) {
         }
         
         std::lock_guard<std::mutex> lguard(_statistics_mutex);
-        _statistics[frame.index()].adding_seconds = overall_timer.elapsed();
-        _statistics[frame.index()].loading_seconds = frame.frame().loading_time();
+        _statistics[frame.index()].adding_seconds = (float)overall_timer.elapsed();
+        _statistics[frame.index()].loading_seconds = (float)frame.frame().loading_time();
     }
 
     class PairProbability {
@@ -706,9 +706,9 @@ bool operator<(long_t frame, const FrameProperties& props) {
         }*/
     }
             
-    std::map<long_t, pv::BlobPtr> Tracker::fill_proximity_grid(grid::ProximityGrid &grid, const std::vector<pv::BlobPtr> &blobs)
+    std::map<uint32_t, pv::BlobPtr> Tracker::fill_proximity_grid(grid::ProximityGrid &grid, const std::vector<pv::BlobPtr> &blobs)
     {
-        std::map<long_t, pv::BlobPtr> bdx_to_ptr;
+        std::map<uint32_t, pv::BlobPtr> bdx_to_ptr;
         size_t calls = 0;
         size_t all_pixels = 0;
         
@@ -719,7 +719,7 @@ bool operator<(long_t frame, const FrameProperties& props) {
             
             auto &size = b->bounds().size();
             const size_t step_size = 2;
-            const size_t step_size_x = max(1, size.width * 0.1);
+            const size_t step_size_x = (size_t)max(1, size.width * 0.1);
             
             all_pixels += b->num_pixels();
             
@@ -984,7 +984,7 @@ bool operator<(long_t frame, const FrameProperties& props) {
         
         size_t available_threads = 1 + (pool ? pool->num_threads() : 0);
         size_t maximal_threads = frame.blobs.size();
-        size_t needed_threads = min(maximal_threads / FAST_SETTINGS(blobs_per_thread), available_threads);
+        size_t needed_threads = min(maximal_threads / (size_t)FAST_SETTINGS(blobs_per_thread), available_threads);
         
         if (maximal_threads > 1 && needed_threads > 1 && available_threads > 1 && pool) {
             size_t used_threads = min(needed_threads, available_threads);
@@ -4204,7 +4204,7 @@ pv::BlobPtr Tracker::find_blob_noisy(std::map<uint32_t, pv::BlobPtr>& blob_to_id
                                 U_EXCEPTION("Range starts at %d, but frame is not set for fish %d.", range.start(), fish->identity().ID());
                             uint32_t start_blob_id = fish->blob(range.start())->blob_id();
                             
-                            file::Path path(tags_path / SETTING(filename).value<file::Path>().filename().to_string() / ("frame"+std::to_string(range.start())+"_blob"+std::to_string(start_blob_id)+".npz"));
+                            file::Path path(tags_path / SETTING(filename).value<file::Path>().filename() / ("frame"+std::to_string(range.start())+"_blob"+std::to_string(start_blob_id)+".npz"));
                             if(!path.remove_filename().exists()) {
                                 if(!path.remove_filename().create_folder())
                                     U_EXCEPTION("Cannot create folder '%S' please check permissions.", &path.remove_filename().str());
diff --git a/Application/src/tracker/tracking/Tracker.h b/Application/src/tracker/tracking/Tracker.h
index 40d0627b338072fdd52533bf9071fa3e53751fc2..0433b59030f1469d0a80e5f212ca2a85f08c29d9 100644
--- a/Application/src/tracker/tracking/Tracker.h
+++ b/Application/src/tracker/tracking/Tracker.h
@@ -302,7 +302,7 @@ CREATE_STRUCT(Settings,
         
     private:
         static void filter_blobs(PPFrame& frame, GenericThreadPool *pool);
-        static std::map<long_t, pv::BlobPtr> fill_proximity_grid(cmn::grid::ProximityGrid&, const std::vector<pv::BlobPtr>& blobs);
+        static std::map<uint32_t, pv::BlobPtr> fill_proximity_grid(cmn::grid::ProximityGrid&, const std::vector<pv::BlobPtr>& blobs);
         void history_split(PPFrame& frame, const std::unordered_set<Individual*>& active_individuals, std::ostream* out = NULL, GenericThreadPool* pool = NULL);
         
         struct split_expectation {