diff --git a/Application/src/ProcessedVideo/pv.cpp b/Application/src/ProcessedVideo/pv.cpp
index ef854de7a8c5391030a9786cd36abc0d768a202e..331a658993deb0dfaaa04df112ea89cdbb2c9a78 100644
--- a/Application/src/ProcessedVideo/pv.cpp
+++ b/Application/src/ProcessedVideo/pv.cpp
@@ -4,6 +4,7 @@
 #include <misc/GlobalSettings.h>
 #include <misc/Timer.h>
 #include <misc/PVBlob.h>
+#include <misc/checked_casts.h>
 
 /**
  * =============================
diff --git a/Application/src/commons/common/file/Path.cpp b/Application/src/commons/common/file/Path.cpp
index 98b4bae2b688378e468980083944c2ac771a75ee..9ec9e430ee220e4fb514cf1177651ad66359e0f2 100644
--- a/Application/src/commons/common/file/Path.cpp
+++ b/Application/src/commons/common/file/Path.cpp
@@ -25,7 +25,7 @@
 #include <filesystem>
 #endif
 
-#include <misc/metastring.h>
+#include <misc/checked_casts.h>
 
 namespace file {
     char Path::os_sep() { return OS_SEP; }
diff --git a/Application/src/commons/common/gui/DrawBase.cpp b/Application/src/commons/common/gui/DrawBase.cpp
index e6b8153c46d571875b784060169e00a4302894c4..5a797887d9986766e16c6e637e08b1de2a7853d9 100644
--- a/Application/src/commons/common/gui/DrawBase.cpp
+++ b/Application/src/commons/common/gui/DrawBase.cpp
@@ -1,5 +1,5 @@
 #include "DrawBase.h"
-#include <misc/metastring.h>
+#include <misc/checked_casts.h>
 
 namespace gui {
     Base *_latest_base = nullptr;
diff --git a/Application/src/commons/common/gui/DrawCVBase.cpp b/Application/src/commons/common/gui/DrawCVBase.cpp
index b25039b898683ee939fe13e4cda4a2a5637d349e..3c4dc97418ba124516d1a95b55ea3ac0474a4cdd 100644
--- a/Application/src/commons/common/gui/DrawCVBase.cpp
+++ b/Application/src/commons/common/gui/DrawCVBase.cpp
@@ -1,5 +1,5 @@
 #include "DrawCVBase.h"
-#include <misc/metastring.h>
+#include <misc/checked_casts.h>
 
 namespace gui {
     IMPLEMENT(CVBase::_static_pixels);
diff --git a/Application/src/commons/common/gui/DrawStructure.cpp b/Application/src/commons/common/gui/DrawStructure.cpp
index f8b2c181ef2ca0f263bd1722ad2710153d47b038..e1882de1d5da7aa389bd36aeb5dca80fca635714 100644
--- a/Application/src/commons/common/gui/DrawStructure.cpp
+++ b/Application/src/commons/common/gui/DrawStructure.cpp
@@ -3,6 +3,7 @@
 #include <gui/types/StaticText.h>
 #include <gui/types/Button.h>
 #include <misc/GlobalSettings.h>
+#include <misc/checked_casts.h>
 
 namespace gui {
     struct ErrorMessage {
diff --git a/Application/src/commons/common/gui/GLImpl.cpp b/Application/src/commons/common/gui/GLImpl.cpp
index ba10ec87c5f4a89c6281c4be4962133b6f1b2baf..b9e1a3ff528f3983f177300ec7798c281effb33d 100644
--- a/Application/src/commons/common/gui/GLImpl.cpp
+++ b/Application/src/commons/common/gui/GLImpl.cpp
@@ -50,6 +50,7 @@ using ImTextureID_t = ImGui_OpenGL2_TextureID;
 
 #include "GLImpl.h"
 #include <misc/Timer.h>
+#include <misc/checked_casts.h>
 
 #define GLIMPL_CHECK_THREAD_ID() check_thread_id( __LINE__ , __FILE__ )
 
@@ -105,8 +106,8 @@ void GLImpl::set_icons(const std::vector<file::Path>& icons) {
         data.push_back(ptr);
         images.push_back(GLFWimage());
         images.back().pixels = ptr->data();
-        images.back().width = ptr->cols;
-        images.back().height = ptr->rows;
+        images.back().width = sign_cast<int>(ptr->cols);
+        images.back().height = sign_cast<int>(ptr->rows);
     }
 
     glfwSetWindowIcon(window, images.size(), images.data());
diff --git a/Application/src/commons/common/gui/IMGUIBase.cpp b/Application/src/commons/common/gui/IMGUIBase.cpp
index d698da4f7881e9c3265a901d1695804951266900..c2221fada385979ca87ba6a7a9f02459bdee8388 100644
--- a/Application/src/commons/common/gui/IMGUIBase.cpp
+++ b/Application/src/commons/common/gui/IMGUIBase.cpp
@@ -30,6 +30,8 @@
 #define GLFW_HAVE_MONITOR_SCALE true
 #endif
 
+#include <misc/checked_casts.h>
+
 namespace gui {
 
 
diff --git a/Application/src/commons/common/gui/types/ScrollableList.h b/Application/src/commons/common/gui/types/ScrollableList.h
index 7fbf461c5afbd36adcd1288875a7f1f50f846bba..9e569e53e97d776f12e31c724861c909692b71c6 100644
--- a/Application/src/commons/common/gui/types/ScrollableList.h
+++ b/Application/src/commons/common/gui/types/ScrollableList.h
@@ -2,7 +2,7 @@
 
 #include <gui/types/Entangled.h>
 #include <gui/DrawSFBase.h>
-#include <misc/metastring.h>
+#include <misc/checked_casts.h>
 
 namespace gui {
     class CustomItem {
diff --git a/Application/src/commons/common/misc/Grid.cpp b/Application/src/commons/common/misc/Grid.cpp
index 274c5372775484fb90f21a29fb2b95cd26275825..55844d903957a33e45afcf2778cc8cadc9dcb7e2 100644
--- a/Application/src/commons/common/misc/Grid.cpp
+++ b/Application/src/commons/common/misc/Grid.cpp
@@ -1,5 +1,5 @@
 #include "Grid.h"
-#include <misc/metastring.h>
+#include <misc/checked_casts.h>
 
 namespace cmn {
 namespace grid {
diff --git a/Application/src/commons/common/misc/checked_casts.h b/Application/src/commons/common/misc/checked_casts.h
new file mode 100644
index 0000000000000000000000000000000000000000..b81197a72929d19217e12ac274e0d23f0d6a1573
--- /dev/null
+++ b/Application/src/commons/common/misc/checked_casts.h
@@ -0,0 +1,184 @@
+#pragma once
+
+#include <types.h>
+#ifndef NDEBUG
+#include <misc/metastring.h>
+#endif
+
+namespace cmn {
+namespace tag {
+struct warn_on_error {};
+struct fail_on_error {};
+}
+
+template<typename T>
+using try_make_unsigned =
+typename std::conditional<
+    std::is_integral<T>::value,
+    std::make_unsigned<T>,
+    double
+>::type;
+
+template<typename T>
+using try_make_signed =
+typename std::conditional<
+    std::is_integral<T>::value,
+    std::make_signed<T>,
+    double
+>::type;
+
+template<typename To, typename From>
+void fail_type(From&& value) {
+#ifndef NDEBUG
+    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);
+#endif
+}
+
+template<typename To, typename From>
+constexpr To sign_cast(From&& value) {
+#ifndef NDEBUG
+    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 (value > std::numeric_limits<ToType>::max())
+                fail_type<To, From>(std::forward<From>(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));
+        }
+    }
+#endif
+    return static_cast<To>(std::forward<From>(value));
+}
+
+template<typename To, typename From>
+constexpr bool check_narrow_cast(const From& value) {
+#ifndef NDEBUG
+    using FromType = typename remove_cvref<From>::type;
+    using ToType = typename remove_cvref<To>::type;
+
+    auto str = Meta::toStr(value);
+    if constexpr (
+        std::is_floating_point<ToType>::value
+        || (std::is_signed<FromType>::value == std::is_signed<ToType>::value && !std::is_floating_point<FromType>::value)
+        )
+    {
+        // unsigned to unsigned
+#ifdef _NARROW_PRINT_VERBOSE
+        auto tstr0 = Meta::name<FromType>();
+        auto tstr1 = Meta::name<ToType>();
+        Debug("Narrowing %S -> %S (same) = %S.", &tstr0, &tstr1, &str);
+#endif
+        return true;
+    }
+    else if constexpr (std::is_floating_point<FromType>::value && std::is_signed<ToType>::value) {
+        using signed_t = int64_t;
+#ifdef _NARROW_PRINT_VERBOSE
+        auto tstr0 = Meta::name<FromType>();
+        auto tstr1 = Meta::name<ToType>();
+        auto tstr2 = Meta::name<signed_t>();
+        Debug("Narrowing %S -> %S | converting to %S and comparing (fs) = %S.", &tstr0, &tstr1, &tstr2, &str);
+#endif
+        return static_cast<signed_t>(value) >= static_cast<signed_t>(std::numeric_limits<To>::min())
+            && static_cast<signed_t>(value) <= static_cast<signed_t>(std::numeric_limits<To>::max());
+    }
+    else if constexpr (std::is_floating_point<FromType>::value && std::is_unsigned<ToType>::value) {
+        using unsigned_t = uint64_t;
+#ifdef _NARROW_PRINT_VERBOSE
+        auto tstr0 = Meta::name<FromType>();
+        auto tstr1 = Meta::name<ToType>();
+        auto tstr2 = Meta::name<unsigned_t>();
+        Debug("Narrowing %S -> %S | converting to %S and comparing (fs) = %S.", &tstr0, &tstr1, &tstr2, &str);
+#endif
+        return value >= FromType(0)
+            && static_cast<unsigned_t>(value) <= static_cast<unsigned_t>(std::numeric_limits<To>::max());
+    }
+    else if constexpr (std::is_unsigned<FromType>::value && std::is_signed<ToType>::value) {
+        // unsigned to signed
+        using signed_t = int64_t;
+#ifdef _NARROW_PRINT_VERBOSE
+        auto tstr0 = Meta::name<FromType>();
+        auto tstr1 = Meta::name<ToType>();
+        auto tstr2 = Meta::name<signed_t>();
+        Debug("Narrowing %S -> %S | converting to %S and comparing (us) = %S.", &tstr0, &tstr1, &tstr2, &str);
+#endif
+        return static_cast<signed_t>(value) < static_cast<signed_t>(std::numeric_limits<To>::max());
+
+    }
+    else {
+        static_assert(std::is_signed<FromType>::value && std::is_unsigned<ToType>::value, "Expecting signed to unsigned conversion");
+        // signed to unsigned
+        using unsigned_t = typename try_make_unsigned<FromType>::type;
+#ifdef _NARROW_PRINT_VERBOSE
+        auto tstr0 = Meta::name<FromType>();
+        auto tstr1 = Meta::name<ToType>();
+        auto tstr2 = Meta::name<unsigned_t>();
+        Debug("Narrowing %S -> %S | converting to %S and comparing (su) = %S.", &tstr0, &tstr1, &tstr2, &str);
+#endif
+        return value >= 0 && static_cast<unsigned_t>(value) <= static_cast<unsigned_t>(std::numeric_limits<To>::max());
+    }
+#else
+    return true;
+#endif
+}
+
+template<typename To, typename From>
+constexpr To narrow_cast(From&& value, struct tag::warn_on_error) {
+#ifndef NDEBUG
+    if (!check_narrow_cast<To, From>(value)) {
+        auto vstr = Meta::toStr(value);
+        auto lstr = Meta::toStr(std::numeric_limits<To>::min());
+        auto rstr = Meta::toStr(std::numeric_limits<To>::max());
+
+        auto tstr = Meta::name<To>();
+        auto fstr = Meta::name<From>();
+        Warning("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr);
+    }
+#endif
+    return static_cast<To>(std::forward<From>(value));
+}
+
+template<typename To, typename From>
+constexpr To narrow_cast(From&& value, struct tag::fail_on_error) {
+#ifndef NDEBUG
+    if (!check_narrow_cast<To, From>(value)) {
+        auto vstr = Meta::toStr(value);
+        auto lstr = Meta::toStr(std::numeric_limits<To>::min());
+        auto rstr = Meta::toStr(std::numeric_limits<To>::max());
+
+        auto tstr = Meta::name<To>();
+        auto fstr = Meta::name<From>();
+        U_EXCEPTION("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr);
+    }
+#endif
+    return static_cast<To>(std::forward<From>(value));
+}
+
+template<typename To, typename From>
+constexpr To narrow_cast(From&& value) {
+    return narrow_cast<To, From>(std::forward<From>(value), tag::warn_on_error{});
+}
+}
diff --git a/Application/src/commons/common/misc/metastring.h b/Application/src/commons/common/misc/metastring.h
index 7eaaa5c55b9d508fc63899d5e82308b20881ed97..35a3384cf253740d6cf24810c14e084b28d042cb 100644
--- a/Application/src/commons/common/misc/metastring.h
+++ b/Application/src/commons/common/misc/metastring.h
@@ -1034,178 +1034,3 @@ namespace cmn {
     }
 }
 
-namespace cmn {
-namespace tag {
-struct warn_on_error {};
-struct fail_on_error {};
-}
-
-template<typename T>
-using try_make_unsigned =
-typename std::conditional<
-	std::is_integral<T>::value,
-	std::make_unsigned<T>,
-	double
->::type;
-
-template<typename T>
-using try_make_signed =
-typename std::conditional<
-	std::is_integral<T>::value,
-	std::make_signed<T>,
-	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) {
-#ifndef NDEBUG
-    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));
-        }
-    }
-#endif
-    return static_cast<To>(std::forward<From>(value));
-}
-
-template<typename To, typename From>
-constexpr bool check_narrow_cast(const From& value) {
-#ifndef NDEBUG
-    using FromType = typename remove_cvref<From>::type;
-    using ToType = typename remove_cvref<To>::type;
-
-    auto str = Meta::toStr(value);
-    if constexpr (
-        std::is_floating_point<ToType>::value
-        || (std::is_signed<FromType>::value == std::is_signed<ToType>::value && !std::is_floating_point<FromType>::value)
-        )
-    {
-        // unsigned to unsigned
-#ifdef _NARROW_PRINT_VERBOSE
-        auto tstr0 = Meta::name<FromType>();
-        auto tstr1 = Meta::name<ToType>();
-        Debug("Narrowing %S -> %S (same) = %S.", &tstr0, &tstr1, &str);
-#endif
-        return true;
-    }
-    else if constexpr (std::is_floating_point<FromType>::value && std::is_signed<ToType>::value) {
-        using signed_t = int64_t;
-#ifdef _NARROW_PRINT_VERBOSE
-        auto tstr0 = Meta::name<FromType>();
-        auto tstr1 = Meta::name<ToType>();
-        auto tstr2 = Meta::name<signed_t>();
-        Debug("Narrowing %S -> %S | converting to %S and comparing (fs) = %S.", &tstr0, &tstr1, &tstr2, &str);
-#endif
-        return static_cast<signed_t>(value) >= static_cast<signed_t>(std::numeric_limits<To>::min())
-            && static_cast<signed_t>(value) <= static_cast<signed_t>(std::numeric_limits<To>::max());
-    }
-    else if constexpr (std::is_floating_point<FromType>::value && std::is_unsigned<ToType>::value) {
-        using unsigned_t = uint64_t;
-#ifdef _NARROW_PRINT_VERBOSE
-        auto tstr0 = Meta::name<FromType>();
-        auto tstr1 = Meta::name<ToType>();
-        auto tstr2 = Meta::name<unsigned_t>();
-        Debug("Narrowing %S -> %S | converting to %S and comparing (fs) = %S.", &tstr0, &tstr1, &tstr2, &str);
-#endif
-        return value >= FromType(0)
-            && static_cast<unsigned_t>(value) <= static_cast<unsigned_t>(std::numeric_limits<To>::max());
-    }
-    else if constexpr (std::is_unsigned<FromType>::value && std::is_signed<ToType>::value) {
-        // unsigned to signed
-        using signed_t = int64_t;
-#ifdef _NARROW_PRINT_VERBOSE
-        auto tstr0 = Meta::name<FromType>();
-        auto tstr1 = Meta::name<ToType>();
-        auto tstr2 = Meta::name<signed_t>();
-        Debug("Narrowing %S -> %S | converting to %S and comparing (us) = %S.", &tstr0, &tstr1, &tstr2, &str);
-#endif
-        return static_cast<signed_t>(value) < static_cast<signed_t>(std::numeric_limits<To>::max());
-
-    }
-    else {
-        static_assert(std::is_signed<FromType>::value && std::is_unsigned<ToType>::value, "Expecting signed to unsigned conversion");
-        // signed to unsigned
-        using unsigned_t = typename try_make_unsigned<FromType>::type;
-#ifdef _NARROW_PRINT_VERBOSE
-        auto tstr0 = Meta::name<FromType>();
-        auto tstr1 = Meta::name<ToType>();
-        auto tstr2 = Meta::name<unsigned_t>();
-        Debug("Narrowing %S -> %S | converting to %S and comparing (su) = %S.", &tstr0, &tstr1, &tstr2, &str);
-#endif
-        return value >= 0 && static_cast<unsigned_t>(value) <= static_cast<unsigned_t>(std::numeric_limits<To>::max());
-    }
-#else
-    return true;
-#endif
-}
-
-template<typename To, typename From>
-constexpr To narrow_cast(From&& value, struct tag::warn_on_error) {
-#ifndef NDEBUG
-    if (!check_narrow_cast<To, From>(value)) {
-        auto vstr = Meta::toStr(value);
-        auto lstr = Meta::toStr(std::numeric_limits<To>::min());
-        auto rstr = Meta::toStr(std::numeric_limits<To>::max());
-
-        auto tstr = Meta::name<To>();
-        auto fstr = Meta::name<From>();
-        Warning("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr);
-    }
-#endif
-    return static_cast<To>(std::forward<From>(value));
-}
-
-template<typename To, typename From>
-constexpr To narrow_cast(From&& value, struct tag::fail_on_error) {
-#ifndef NDEBUG
-    if (!check_narrow_cast<To, From>(value)) {
-        auto vstr = Meta::toStr(value);
-        auto lstr = Meta::toStr(std::numeric_limits<To>::min());
-        auto rstr = Meta::toStr(std::numeric_limits<To>::max());
-
-        auto tstr = Meta::name<To>();
-        auto fstr = Meta::name<From>();
-        U_EXCEPTION("Value '%S' in narrowing conversion of %S -> %S is not within limits [%S,%S].", &vstr, &fstr, &tstr, &lstr, &rstr);
-    }
-#endif
-    return static_cast<To>(std::forward<From>(value));
-}
-
-template<typename To, typename From>
-constexpr To narrow_cast(From&& value) {
-    return narrow_cast<To, From>(std::forward<From>(value), tag::warn_on_error{});
-}
-}
diff --git a/Application/src/commons/common/video/GenericVideo.cpp b/Application/src/commons/common/video/GenericVideo.cpp
index 8c3bb02d61838b22771f65db1b43398b4ce56c44..82e861be676bf872ed0e036761cf5d4531601cc5 100644
--- a/Application/src/commons/common/video/GenericVideo.cpp
+++ b/Application/src/commons/common/video/GenericVideo.cpp
@@ -3,6 +3,7 @@
 #include <misc/GlobalSettings.h>
 #include <grabber/default_config.h>
 #include <misc/Image.h>
+#include <misc/checked_casts.h>
 
 using namespace cmn;
 
diff --git a/Application/src/commons/common/video/VideoSource.cpp b/Application/src/commons/common/video/VideoSource.cpp
index d9ca985f9569dba8d335259ccfff338d430e3df1..80bd174d461383a3a3a8a5307bd99772aba364ad 100644
--- a/Application/src/commons/common/video/VideoSource.cpp
+++ b/Application/src/commons/common/video/VideoSource.cpp
@@ -4,6 +4,7 @@
 #include <file/Path.h>
 #include <misc/GlobalSettings.h>
 #include <misc/ThreadPool.h>
+#include <misc/checked_casts.h>
 
 using namespace cmn;
 
@@ -534,7 +535,7 @@ void VideoSource::generate_average(cv::Mat &av, uint64_t) {
         }
     }
     
-    Debug("generating average in threads step %d for %d files (%d per file)", step, _files_in_seq.size(), frames_per_file);
+    Debug("generating average in threads step %lu for %lu files (%lu per file)", step, _files_in_seq.size(), frames_per_file);
     
     std::mutex mutex;
     GenericThreadPool pool(cmn::hardware_concurrency(), [](auto e) { std::rethrow_exception(e); }, "AverageImage");
diff --git a/Application/src/grabber/default_config.cpp b/Application/src/grabber/default_config.cpp
index ae4ca5554766207eb6da5404ccda2d041d0aa8a2..3afaf6226a8d9250a149e4821aa5b4b2d2ee5c11 100644
--- a/Application/src/grabber/default_config.cpp
+++ b/Application/src/grabber/default_config.cpp
@@ -119,7 +119,7 @@ namespace default_config {
         CONFIG("equalize_histogram", false, "Equalizes the histogram of the image before thresholding and background subtraction.");
         CONFIG("quit_after_average", false, "If set to true, this will terminate the program directly after generating (or loading) a background average image.", STARTUP);
         CONFIG("averaging_method", averaging_method_t::mean, "Determines the way in which the background samples are combined. The background generated in the process will be used to subtract background from foreground objects during conversion.");
-        CONFIG("average_samples", int(100), "Number of samples taken to generate an average image. Usually fewer are necessary for `average_method`s max, and min.");
+        CONFIG("average_samples", uint32_t(100), "Number of samples taken to generate an average image. Usually fewer are necessary for `average_method`s max, and min.");
         CONFIG("reset_average", false, "If set to true, the average will be regenerated using the live stream of images (video or camera).");
         
         CONFIG("video_size", Size2(-1,-1), "Is set to the dimensions of the resulting image.", SYSTEM);
diff --git a/Application/src/grabber/gui.cpp b/Application/src/grabber/gui.cpp
index 1dd9b1b37c1ab386ea84001b9b55dbe6fbeeb93f..37f8de6490e8c99497e182bd01279c2035877aa0 100644
--- a/Application/src/grabber/gui.cpp
+++ b/Application/src/grabber/gui.cpp
@@ -336,9 +336,9 @@ 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<uint32_t>())+")", 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.8f, 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());
+            base.text("waiting for frame...", Vec2(_size.width/2, _size.height/2), Red, Font(0.8f, Align::Center), base.scale().reciprocal());
         }
     }
     
@@ -361,7 +361,7 @@ void GUI::draw(gui::DrawStructure &base) {
             text_color = Black;
         }
     }
-    base.text(info_text(), Vec2(20, 10), text_color, Font(0.7), base.scale().reciprocal());
+    base.text(info_text(), Vec2(20, 10), text_color, Font(0.7f), base.scale().reciprocal());
     base.draw_log_messages();
     
     if(_grabber.tracker_instance()) {
diff --git a/Application/src/tracker/VideoOpener.cpp b/Application/src/tracker/VideoOpener.cpp
index 53f1dcdcd2aa5568b8563d5ab34587b03769a20a..86d4b526037120315bb94b1409db532b85e9fbf3 100644
--- a/Application/src/tracker/VideoOpener.cpp
+++ b/Application/src/tracker/VideoOpener.cpp
@@ -392,7 +392,7 @@ VideoOpener::VideoOpener() {
                 if(!contains(_raw_info->children(), (Drawable*)_loading_text.get()))
                     _raw_info->add_child(2, _loading_text);
                 //_loading_text->set_pos(_screenshot->pos());
-                _loading_text->set_txt("generating average ("+Meta::toStr(min(TEMP_SETTING(average_samples).value<int>(), (int)_buffer->_number_samples.load()))+"/"+TEMP_SETTING(average_samples).get().valueString()+")");
+                _loading_text->set_txt("generating average ("+Meta::toStr(min(TEMP_SETTING(average_samples).value<uint32_t>(), _buffer->_number_samples.load()))+"/"+TEMP_SETTING(average_samples).get().valueString()+")");
                 
             } else if(contains(_raw_info->children(), (Drawable*)_loading_text.get())) {
                 _raw_info->remove_child(_loading_text);
@@ -498,7 +498,7 @@ void VideoOpener::BufferedVideo::restart_background() {
         
         _terminated_background_task = false;
         
-        uint step = max(1u, uint(background_video->length() / max(2u, uint(TEMP_SETTING(average_samples).value<int>()))));
+        uint step = max(1u, uint(background_video->length() / max(2u, uint(TEMP_SETTING(average_samples).value<uint32_t>()))));
         cv::Mat flt, img;
         _number_samples = 0;
         
diff --git a/Application/src/tracker/gui/IdentityHeatmap.cpp b/Application/src/tracker/gui/IdentityHeatmap.cpp
index 6b28235899f722b8e54a10d5b16e0ec2d94b80d1..78182bbaae8b081f9a75cc2f0037daa4086ef37c 100644
--- a/Application/src/tracker/gui/IdentityHeatmap.cpp
+++ b/Application/src/tracker/gui/IdentityHeatmap.cpp
@@ -3,6 +3,7 @@
 #include <tracker/gui/gui.h>
 #include <tracking/Individual.h>
 #include <misc/cnpy_wrapper.h>
+#include <misc/checked_casts.h>
 
 namespace gui {
 namespace heatmap {
diff --git a/Application/src/tracker/misc/EventAnalysis.cpp b/Application/src/tracker/misc/EventAnalysis.cpp
index 575dfb1872b9a3527e6f4c69f80680a1acec9806..3afb5a9b778653e56f8e13f7555d6d59495160db 100644
--- a/Application/src/tracker/misc/EventAnalysis.cpp
+++ b/Application/src/tracker/misc/EventAnalysis.cpp
@@ -2,6 +2,7 @@
 #include <tracking/Tracker.h>
 #include <numeric>
 #include <misc/Timer.h>
+#include <misc/checked_casts.h>
 
 namespace track {
 namespace EventAnalysis {
diff --git a/Application/src/tracker/misc/Output.cpp b/Application/src/tracker/misc/Output.cpp
index 1a7b366c36133db6d309b34018d970e30dd5a77e..500b9a67759244f8e1b43cc0c6bfaa45b0c841bb 100644
--- a/Application/src/tracker/misc/Output.cpp
+++ b/Application/src/tracker/misc/Output.cpp
@@ -6,6 +6,7 @@
 #include <lzo/minilzo.h>
 #include <gui/gui.h>
 #include <gui/WorkProgress.h>
+#include <misc/checked_casts.h>
 
 using namespace track;
 typedef int64_t data_long_t;
diff --git a/Application/src/tracker/misc/OutputLibrary.cpp b/Application/src/tracker/misc/OutputLibrary.cpp
index c2f4f708c5b26756cfbe8cbd9d8f84729a59877c..73a770ee8f1c21c6ab6a7605ca7e717fa46e4629 100644
--- a/Application/src/tracker/misc/OutputLibrary.cpp
+++ b/Application/src/tracker/misc/OutputLibrary.cpp
@@ -4,6 +4,7 @@
 #include <misc/EventAnalysis.h>
 #include <file/CSVExport.h>
 #include <misc/cnpy_wrapper.h>
+#include <misc/checked_casts.h>
 
 namespace Output {
     using namespace gui;
diff --git a/Application/src/tracker/tracking/Accumulation.cpp b/Application/src/tracker/tracking/Accumulation.cpp
index 97be1f5c34a0ebd3352e3ee34c0e49b701120b4e..04c94daf0d8ab826e0b9515beb41bcaef090dd3e 100644
--- a/Application/src/tracker/tracking/Accumulation.cpp
+++ b/Application/src/tracker/tracking/Accumulation.cpp
@@ -12,6 +12,7 @@
 #include <misc/default_settings.h>
 #include <gui/Graph.h>
 #include <gui/types/StaticText.h>
+#include <misc/checked_casts.h>
 
 namespace track {
 using namespace file;
@@ -258,14 +259,14 @@ std::tuple<bool, std::map<long_t, long_t>> Accumulation::check_additional_range(
     
     for(auto && [id, tup] : averages) {
         auto & [samples, values] = tup;
-        long_t max_index = -1;
+        int64_t max_index = -1;
         float max_p = 0;
         if(samples > 0) {
             for(auto & v : values)
                 v /= samples;
         }
         
-        for(long_t i=0; i<(long_t)values.size(); ++i) {
+        for(uint32_t i=0; i<values.size(); ++i) {
             auto v = values[i];
             if(v > max_p) {
                 max_index = i;
@@ -424,7 +425,7 @@ std::tuple<std::shared_ptr<TrainingData>, std::vector<Image::Ptr>, std::map<long
         
         std::map<long_t, std::set<long_t>> disc_individuals_per_frame;
         
-        for(long_t frame = analysis_range.start; frame <= analysis_range.end; frame += max(1, analysis_range.length() * 0.003))
+        for(long_t frame = analysis_range.start; frame <= analysis_range.end; frame += max(1, analysis_range.length() / 333))
         {
             if(frame < Tracker::start_frame())
                 continue;
diff --git a/Application/src/tracker/tracking/Export.cpp b/Application/src/tracker/tracking/Export.cpp
index 1adab065be3d69228a7e76e839637617b575d8c6..fd37d7558ce6db0e9700bf5cbe15aef813e0341d 100644
--- a/Application/src/tracker/tracking/Export.cpp
+++ b/Application/src/tracker/tracking/Export.cpp
@@ -10,6 +10,7 @@
 #include <misc/cnpy_wrapper.h>
 #include <tracker/misc/MemoryStats.h>
 #include <pv.h>
+#include <misc/checked_casts.h>
 
 #if WIN32
 #include <io.h>
diff --git a/Application/src/tracker/tracking/Outline.cpp b/Application/src/tracker/tracking/Outline.cpp
index 63a4420fca715ff5de258ade6d851dbecf13ec08..19bd5ab6bc29ae4ced175bf7183cb150a8aa1e02 100644
--- a/Application/src/tracker/tracking/Outline.cpp
+++ b/Application/src/tracker/tracking/Outline.cpp
@@ -12,6 +12,7 @@
 #include <gui/DrawCVBase.h>
 #include <misc/default_config.h>
 #include <misc/create_struct.h>
+#include <misc/checked_casts.h>
 
 using namespace track;
 //#define _DEBUG_MEMORY