diff --git a/common/src/util.cpp b/common/src/util.cpp
index 3b8aa964bfb72d03914b4071608c7d0b5ddc6026..a40362ca5b57470c7e5e8ee712166c7ae675e2b2 100644
--- a/common/src/util.cpp
+++ b/common/src/util.cpp
@@ -58,9 +58,12 @@ util::utf8string util::splitAsUtf8(std::string_view s)
     }
     if (currentPtr - beginPtr > 4 || currentPtr - beginPtr == 0)
       myThrow(fmt::format("Invalid utf8 character at index {}", beginPtr-s.data()));
+
     utf8char c;
+
     for (int i = 0; i < currentPtr - beginPtr; i++)
-      ((char*)&c)[i] = beginPtr[i];
+      c[i] = beginPtr[i];
+
     beginPtr = currentPtr;
     result.push_back(c);
   }
diff --git a/torch_modules/src/Submodule.cpp b/torch_modules/src/Submodule.cpp
index 2be33f7bd165e8fb32a12283284320db01eda065..e58ff2849effc45d778d62eaae489b4c17f2ae89 100644
--- a/torch_modules/src/Submodule.cpp
+++ b/torch_modules/src/Submodule.cpp
@@ -67,6 +67,9 @@ std::function<std::string(const std::string &)> Submodule::getFunction(const std
 {
   static auto prefix = [](const std::string & s, int length)
   {
+    if (s.size() == 0)
+      return s;
+
     util::utf8string utf8s = util::splitAsUtf8(s);
     util::utf8string prefix(utf8s.begin(), std::min(utf8s.end(),utf8s.begin()+length));
     return fmt::format("{}", prefix);
@@ -74,6 +77,9 @@ std::function<std::string(const std::string &)> Submodule::getFunction(const std
 
   static auto suffix = [](const std::string & s, int length)
   {
+    if (s.size() == 0)
+      return s;
+
     util::utf8string utf8s = util::splitAsUtf8(s);
     util::utf8string suffix(std::max(utf8s.begin(), utf8s.end()-length), utf8s.end());
     return fmt::format("{}", suffix);