diff --git a/miosix/kernel/cpu_time_counter.cpp b/miosix/kernel/cpu_time_counter.cpp
index 854a350769bc172aab5b32f9b963be799c56e69e..3788053a18ab7135c16814d083c04a5dc4db9192 100644
--- a/miosix/kernel/cpu_time_counter.cpp
+++ b/miosix/kernel/cpu_time_counter.cpp
@@ -53,13 +53,12 @@ void CPUTimeCounter::PKremoveDeadThreads()
 {
     Thread *prev = nullptr;
     Thread *cur = head;
-    while (cur) {
-        if (cur->flags.isDeleted()) {
-            if (prev) {
-                prev->timeCounterData.next = cur->timeCounterData.next;
-            } else {
-                head = cur->timeCounterData.next;
-            }
+    while(cur)
+    {
+        if(cur->flags.isDeleted())
+        {
+            if(prev) prev->timeCounterData.next = cur->timeCounterData.next;
+            else head = cur->timeCounterData.next;
             nThreads--;
         } else {
             prev = cur;
diff --git a/miosix/util/util.cpp b/miosix/util/util.cpp
index b40103269886d6bb930950d5abb0c1fffa389e3d..2ff5f33f8b2da106755f6cae5ee711ae00bd5763 100644
--- a/miosix/util/util.cpp
+++ b/miosix/util/util.cpp
@@ -163,6 +163,24 @@ void memDump(const void *start, int len)
 
 #ifdef WITH_CPU_TIME_COUNTER
 
+static void printSingleThreadInfo(Thread *self, Thread *thread,
+    int approxDt, long long newTime, long long oldTime, bool isIdleThread,
+    bool isNewThread)
+{
+    long long threadDt = newTime - oldTime;
+    int perc = static_cast<int>(threadDt >> 16) * 100 / approxDt;
+    iprintf("%p %10lld ns (%2d.%1d%%)", thread, threadDt, perc / 10, perc % 10);
+    if(isIdleThread)
+    {
+        iprintf(" (idle)");
+        isIdleThread = false;
+    } else if(thread == self) {
+        iprintf(" (cur)");
+    }
+    if(isNewThread) iprintf(" new");
+    iprintf("\n");
+}
+
 //
 // CPUProfiler class
 //
@@ -174,26 +192,6 @@ long long CPUProfiler::update()
     return snapshots[lastSnapshotIndex].time;
 }
 
-static void printSingleThreadInfo(
-    Thread *self, Thread *thread,
-    long long approxDt, long long newTime, long long oldTime, bool isIdleThread,
-    bool isNewThread)
-{
-    long long threadDt = newTime - oldTime;
-    long perc = (long)(threadDt >> 16) * 100 / approxDt;
-    iprintf("%p %10lld ns (%2ld.%1ld%%)", thread, threadDt, perc / 10, perc % 10);
-    if (isIdleThread) {
-        iprintf(" (idle)");
-        isIdleThread = false;
-    } else if (thread == self) {
-        iprintf(" (cur)");
-    }
-    if (isNewThread) {
-        iprintf(" new");
-    }
-    iprintf("\n");
-}
-
 void CPUProfiler::print()
 {
     Snapshot& oldSnap = snapshots[lastSnapshotIndex ^ 1];
@@ -201,7 +199,7 @@ void CPUProfiler::print()
     std::vector<CPUTimeCounter::Data>& oldInfo = oldSnap.threadData;
     std::vector<CPUTimeCounter::Data>& newInfo = newSnap.threadData;
     long long dt = newSnap.time - oldSnap.time;
-    long approxDt = (long)(dt >> 16) / 10;
+    int approxDt = static_cast<int>(dt >> 16) / 10;
     Thread *self = Thread::getCurrentThread();
 
     iprintf("%d threads, last interval %lld ns\n", newInfo.size(), dt);
@@ -211,9 +209,11 @@ void CPUProfiler::print()
     auto newIt = newInfo.begin();
     // CPUTimeCounter always returns the idle thread as the first thread
     bool isIdleThread = true;
-    while (newIt != newInfo.end() && oldIt != oldInfo.end()) {
+    while(newIt != newInfo.end() && oldIt != oldInfo.end())
+    {
         // Skip old threads that were killed
-        while (newIt->thread != oldIt->thread) {
+        while(newIt->thread != oldIt->thread)
+        {
             iprintf("%p killed\n", oldIt->thread);
             oldIt++;
         }
@@ -225,13 +225,15 @@ void CPUProfiler::print()
         oldIt++;
     }
     // Skip last killed threads
-    while (oldIt != oldInfo.end()) {
+    while(oldIt != oldInfo.end())
+    {
         iprintf("%p killed\n", oldIt->thread);
         isIdleThread = false;
         oldIt++;
     }
     // Print info about newly created threads
-    while (newIt != newInfo.end()) {
+    while(newIt != newInfo.end())
+    {
         printSingleThreadInfo(self, newIt->thread, approxDt, newIt->usedCpuTime,
             0, isIdleThread, true);
         isIdleThread = false;
@@ -257,7 +259,7 @@ void CPUProfiler::Snapshot::collect()
 
             // If the number of threads changed, try again
             unsigned int nThreads2 = CPUTimeCounter::getThreadCount();
-            if (nThreads2 != nThreads)
+            if(nThreads2 != nThreads)
                 continue;
             // Otherwise, stop trying
             success = true;
@@ -272,16 +274,17 @@ void CPUProfiler::Snapshot::collect()
             auto i2 = CPUTimeCounter::PKbegin();
             do
                 *i1++ = *i2++;
-            while (i2 != CPUTimeCounter::PKend());
+            while(i2 != CPUTimeCounter::PKend());
         }
-    } while (!success);
+    } while(!success);
 }
 
 void CPUProfiler::thread(long long nsInterval)
 {
     CPUProfiler profiler;
     long long t = profiler.update();
-    while (!Thread::testTerminate()) {
+    while(!Thread::testTerminate())
+    {
         t += nsInterval;
         Thread::nanoSleepUntil(t);
         profiler.update();
diff --git a/miosix/util/util.h b/miosix/util/util.h
index 9b1e0349b199b3c5f5f869e11ffec611cb6a686f..429efb3b9730820a51151d3dcb05678651c51515 100644
--- a/miosix/util/util.h
+++ b/miosix/util/util.h
@@ -124,7 +124,8 @@ void memDump(const void *start, int len);
  * 
  *      CPUProfiler p;
  *      long long t = p.update();
- *      while (...) {
+ *      while (...)
+ *      {
  *          t += 1000000000LL;
  *          Thread::nanoSleepUntil(t);
  *          p.update();
@@ -150,7 +151,7 @@ public:
     /**
      * Construct a new profiler object.
      */
-    CPUProfiler() {};
+    CPUProfiler() {}
 
     /**
      * Update the profiler status with the latest information about all
@@ -180,7 +181,8 @@ private:
      * Structure containing a snapshot of the CPU data information returned
      * by CPUTimeCounter for each thread.
      */
-    struct Snapshot {
+    struct Snapshot
+    {
         /// The thread data objects, one per thread
         std::vector<CPUTimeCounter::Data> threadData;
         /// The time (in ns) at which the snapshot was collected