diff --git a/include/usb-dbg.hpp b/include/usb-dbg.hpp
index dd552b6..1344150 100644
--- a/include/usb-dbg.hpp
+++ b/include/usb-dbg.hpp
@@ -36,11 +36,16 @@
 namespace ipmi
 {
 
-#define JSON_POST_DATA_FILE "/usr/share/lcd-debug/post_desc.json"
-#define JSON_GPIO_DATA_FILE "/usr/share/lcd-debug/gpio_desc.json"
-#define JSON_SENSOR_NAMES_FILE "/usr/share/lcd-debug/cri_sensors.json"
+static constexpr bool DEBUG = false;
 
-#define ETH_INTF_NAME "eth0"
+static constexpr auto JSON_POST_DATA_FILE =
+    "/usr/share/lcd-debug/post_desc.json";
+static constexpr auto JSON_GPIO_DATA_FILE =
+    "/usr/share/lcd-debug/gpio_desc.json";
+static constexpr auto JSON_SENSOR_NAMES_FILE =
+    "/usr/share/lcd-debug/cri_sensors.json";
+
+static constexpr auto ETH_INTF_NAME = "eth0";
 
 #define ESCAPE "\x1B"
 #define ESC_BAT ESCAPE "B"
@@ -49,70 +54,58 @@
 #define ESC_ALT ESCAPE "[5;7m"
 #define ESC_RST ESCAPE "[m"
 
-#define LINE_DELIMITER '\x1F'
+static constexpr char LINE_DELIMITER = '\x1F';
 
-#define FRAME_BUFF_SIZE 4096
-#define FRAME_PAGE_BUF_SIZE 256
+static constexpr size_t FRAME_BUFF_SIZE = 4096;
+static constexpr size_t FRAME_PAGE_BUF_SIZE = 256;
+
 #define FRU_ALL 0
-#define MAX_VALUE_LEN 64
 
-#define DEBUG_GPIO_KEY "GpioDesc"
-#define GPIO_ARRAY_SIZE 4
-#define GPIO_PIN_INDEX 0
-#define GPIO_LEVEL_INDEX 1
-#define GPIO_DEF_INDEX 2
-#define GPIO_DESC_INDEX 3
-#define BMC_POSITION 0
-#define MAX_HOST_POS 4
+static constexpr auto DEBUG_GPIO_KEY = "GpioDesc";
+static constexpr auto GPIO_ARRAY_SIZE = 4;
+static constexpr auto GPIO_PIN_INDEX = 0;
+static constexpr auto GPIO_LEVEL_INDEX = 1;
+static constexpr auto GPIO_DEF_INDEX = 2;
+static constexpr auto GPIO_DESC_INDEX = 3;
 
-/* Used for systems which do not specifically have a
- * phase, and we want to ignore the phase provided by the
- * debug card */
-#define PHASE_ANY 0xff
+static constexpr size_t BMC_POSITION = 0;
 
-static constexpr bool DEBUG = false;
-static const uint8_t meAddress = 1;
+static constexpr uint8_t meAddress = 1;
 static constexpr uint8_t lun = 0;
 
 using IpmbMethodType =
     std::tuple<int, uint8_t, uint8_t, uint8_t, uint8_t, std::vector<uint8_t>>;
 
-typedef struct _sensor_desc
-{
-    char name[16];
-    uint8_t sensor_num;
-    char unit[5];
-    uint8_t fru;
-    uint8_t disp_prec;
-} sensor_desc_t;
-
 struct frame
 {
     char title[32];
     size_t max_size;
     size_t max_page;
     char* buf;
-    uint16_t idx_head, idx_tail;
-    uint8_t line_per_page;
-    uint8_t line_width;
-    uint16_t lines, pages;
+    size_t idx_head, idx_tail;
+    size_t line_per_page;
+    size_t line_width;
+    size_t lines, pages;
     uint8_t esc_sts;
-    uint8_t overwrite;
+    bool overwrite;
     time_t mtime;
-    frame() : buf(NULL), pages(0), mtime(0) {}
-    int init(size_t size);
-    int append(const char* string, int indent);
-    int insert(const char* string, int indent);
-    int getPage(int page, char* page_buf, size_t page_buf_size);
-    int isFull();
-    int isEscSeq(char chr);
-    int parse(char* buf, size_t buf_size, const char* input, int indent);
+
+    frame() : buf(nullptr), pages(0), mtime(0) {}
+
+    void init(size_t size = FRAME_BUFF_SIZE);
+    void append(const std::string& str, size_t indent = 0);
+    int getPage(size_t page, char* page_buf, size_t page_buf_size);
+    bool isFull() const;
+    bool isEscSeq(char chr);
+
+  private:
+    auto parse(const std::string& input, size_t indent) -> std::string;
 };
 
-struct frame frame_info;
-struct frame frame_sel;
-struct frame frame_snr;
-struct frame frame_postcode;
+frame frame_info;
+frame frame_sel;
+frame frame_snr;
+frame frame_postcode;
 
 enum class panel : uint8_t
 {
diff --git a/src/usb-dbg.cpp b/src/usb-dbg.cpp
index c8f5a94..a61b59c 100644
--- a/src/usb-dbg.cpp
+++ b/src/usb-dbg.cpp
@@ -117,7 +117,7 @@
 }
 
 // return 0 on seccuess
-int frame::init(size_t size)
+void frame::init(size_t size)
 {
     // Reset status
     idx_head = idx_tail = 0;
@@ -125,13 +125,12 @@
     esc_sts = 0;
     pages = 1;
 
-    if (buf != NULL && max_size == size)
+    if (buf != nullptr && max_size == size)
     {
-        // reinit
-        return 0;
+        return;
     }
 
-    if (buf != NULL && max_size != size)
+    if (buf != nullptr && max_size != size)
     {
         delete[] buf;
     }
@@ -142,28 +141,15 @@
     max_page = size;
     line_per_page = 7;
     line_width = 16;
-    overwrite = 0;
+    overwrite = false;
 
-    if (buf)
-        return 0;
-    else
-        return -1;
+    return;
 }
 
 // return 0 on seccuess
-int frame::append(const char* string, int indent)
+void frame::append(const std::string& str, size_t indent)
 {
-    const size_t buf_size = 128;
-    char lbuf[buf_size];
-    char* ptr;
-    int ret;
-
-    ret = parse(lbuf, buf_size, string, indent);
-
-    if (ret < 0)
-        return ret;
-
-    for (ptr = lbuf; *ptr != '\0'; ptr++)
+    for (auto ch : parse(str, indent))
     {
         if (isFull())
         {
@@ -174,11 +160,13 @@
                 idx_head = (idx_head + 1) % max_size;
             }
             else
-                return -1;
+            {
+                throw std::overflow_error("No room in buffer");
+            }
         }
 
-        buf[idx_tail] = *ptr;
-        if (*ptr == LINE_DELIMITER)
+        buf[idx_tail] = ch;
+        if (ch == LINE_DELIMITER)
             lines++;
 
         idx_tail = (idx_tail + 1) % max_size;
@@ -189,71 +177,27 @@
     if (pages > max_page)
         pages = max_page;
 
-    return 0;
-}
-
-// return 0 on seccuess
-int frame::insert(const char* string, int indent)
-{
-    const size_t buf_size = 128;
-    char lbuf[buf_size];
-    char* ptr;
-    int ret;
-    int i;
-
-    ret = parse(lbuf, buf_size, string, indent);
-
-    if (ret < 0)
-        return ret;
-
-    for (i = strlen(lbuf) - 1; i >= 0; i--)
-    {
-        ptr = &lbuf[i];
-        if (isFull())
-        {
-            if (overwrite)
-            {
-                idx_tail = (idx_tail + max_size - 1) % max_size;
-                if (buf[idx_tail] == LINE_DELIMITER)
-                    lines--;
-            }
-            else
-                return -1;
-        }
-
-        idx_head = (idx_head + max_size - 1) % max_size;
-
-        buf[idx_head] = *ptr;
-        if (*ptr == LINE_DELIMITER)
-            lines++;
-    }
-
-    pages = (lines / line_per_page) + ((lines % line_per_page) ? 1 : 0);
-
-    if (pages > max_page)
-        pages = max_page;
-
-    return 0;
+    return;
 }
 
 // return page size
-int frame::getPage(int page, char* page_buf, size_t page_buf_size)
+int frame::getPage(size_t page, char* page_buf, size_t page_buf_size)
 {
     int ret;
     uint16_t line = 0;
     uint16_t idx, len;
 
-    if (buf == NULL)
+    if (buf == nullptr)
         return -1;
 
     // 1-based page
     if (page > pages || page < 1)
         return -1;
 
-    if (page_buf == NULL || page_buf_size == 0)
+    if (page_buf == nullptr || page_buf_size == 0)
         return -1;
 
-    ret = snprintf(page_buf, 17, "%-10s %02d/%02d", title, page, pages);
+    ret = snprintf(page_buf, 17, "%-10s %02zd/%02zd", title, page, pages);
     len = strlen(page_buf);
     if (ret < 0)
         return -1;
@@ -287,20 +231,19 @@
     return len;
 }
 
-// return 1 for frame buffer full
-int frame::isFull()
+bool frame::isFull() const
 {
-    if (buf == NULL)
-        return -1;
+    if (buf == nullptr)
+        return true;
 
     if ((idx_tail + 1) % max_size == idx_head)
-        return 1;
+        return true;
     else
-        return 0;
+        return false;
 }
 
 // return 1 for Escape Sequence
-int frame::isEscSeq(char chr)
+bool frame::isEscSeq(char chr)
 {
     uint8_t curr_sts = esc_sts;
 
@@ -314,77 +257,47 @@
         esc_sts = 0;
 
     if (curr_sts || esc_sts)
-        return 1;
+        return true;
     else
-        return 0;
+        return false;
 }
 
 // return 0 on success
-int frame::parse(char* lbuf, size_t buf_size, const char* input, int indent)
+auto frame::parse(const std::string& input, size_t indent) -> std::string
 {
-    uint8_t pos, esc;
-    size_t i;
-    const char *in, *end;
+    if (indent > line_width)
+        return {};
 
-    if (buf == NULL || input == NULL)
-        return -1;
+    std::string result;
+    size_t linepos = 0;
 
-    if (indent >= line_width || indent < 0)
-        return -1;
-
-    in = input;
-    end = in + strlen(input);
-    pos = 0; // line position
-    esc = 0; // escape state
-    i = 0;   // buf index
-    while (in != end)
+    for (auto ch : input)
     {
-        if (i >= buf_size)
-            break;
+        // Pad the line.
+        result.append(indent, ' ');
+        linepos = indent;
 
-        if (pos < indent)
+        bool esc = isEscSeq(ch);
+
+        // Check if new line is needed.
+        if (!esc && linepos == line_width)
         {
-            // fill indent
-            lbuf[i++] = ' ';
-            pos++;
-            continue;
+            result.push_back(LINE_DELIMITER);
+            result.append(indent, ' ');
+            linepos = indent;
         }
 
-        esc = isEscSeq(*in);
-
-        if (!esc && pos == line_width)
-        {
-            lbuf[i++] = LINE_DELIMITER;
-            pos = 0;
-            continue;
-        }
-
+        // Insert character.
+        result.push_back(ch);
         if (!esc)
-            pos++;
-
-        // fill input data
-        lbuf[i++] = *(in++);
+            ++linepos;
     }
 
-    // padding
-    while (pos <= line_width)
-    {
-        if (i >= buf_size)
-            break;
-        if (pos < line_width)
-            lbuf[i++] = ' ';
-        else
-            lbuf[i++] = LINE_DELIMITER;
-        pos++;
-    }
+    // Fill out remaining line.
+    result.append(line_width - linepos, ' ');
+    result.push_back(LINE_DELIMITER);
 
-    // full
-    if (i >= buf_size)
-        return -1;
-
-    lbuf[i++] = '\0';
-
-    return 0;
+    return result;
 }
 
 static int chk_cri_sel_update(uint8_t* cri_sel_up)
@@ -410,7 +323,7 @@
     }
     else
     {
-        if (frame_sel.buf == NULL || frame_sel.lines != 0 || pre_pos != pos)
+        if (frame_sel.buf == nullptr || frame_sel.lines != 0 || pre_pos != pos)
         {
             *cri_sel_up = 1;
         }
@@ -729,7 +642,7 @@
         // Only update frame data while getting page 1
 
         // initialize and clear frame
-        frame_info.init(FRAME_BUFF_SIZE);
+        frame_info.init();
         snprintf(frame_info.title, 32, "SYS_Info");
 
         bool platform = isMultiHostPlatform();
@@ -741,35 +654,35 @@
         getMaxHostPosition(maxPosition);
         if (hostPosition == BMC_POSITION || hostInstances == "0")
         {
-            frame_info.append("FRU:spb", 0);
+            frame_info.append("FRU:spb");
         }
         else if (hostPosition != BMC_POSITION && hostPosition <= maxPosition)
         {
             std::string data = "FRU:slot" + std::to_string(hostPosition);
-            frame_info.append(data.c_str(), 0);
+            frame_info.append(data);
         }
 
         // FRU
         std::string data;
-        frame_info.append("SN:", 0);
+        frame_info.append("SN:");
         if (getFruData(data, serialName) != 0)
         {
             data = "Not Found";
         }
-        frame_info.append(data.c_str(), 1);
-        frame_info.append("PN:", 0);
+        frame_info.append(data, 1);
+        frame_info.append("PN:");
         if (getFruData(data, partName) != 0)
         {
             data = "Not Found";
         }
-        frame_info.append(data.c_str(), 1);
+        frame_info.append(data, 1);
 
         // LAN
         getNetworkData(3, line_buff);
-        frame_info.append("BMC_IP:", 0);
+        frame_info.append("BMC_IP:");
         frame_info.append(line_buff, 1);
         getNetworkData(59, line_buff);
-        frame_info.append("BMC_IPv6:", 0);
+        frame_info.append("BMC_IPv6:");
         frame_info.append(line_buff, 1);
 
         // BMC ver
@@ -782,8 +695,8 @@
                 if (line.find(verDel) != std::string::npos)
                 {
                     std::string bmcVer = line.substr(verDel.size());
-                    frame_info.append("BMC_FW_ver:", 0);
-                    frame_info.append(bmcVer.c_str(), 1);
+                    frame_info.append("BMC_FW_ver:");
+                    frame_info.append(bmcVer, 1);
                     break;
                 }
             }
@@ -795,8 +708,8 @@
             std::string biosVer;
             if (getBiosVer(biosVer, hostPosition) == 0)
             {
-                frame_info.append("BIOS_FW_ver:", 0);
-                frame_info.append(biosVer.c_str(), 1);
+                frame_info.append("BIOS_FW_ver:");
+                frame_info.append(biosVer, 1);
             }
         }
 
@@ -804,20 +717,20 @@
         // Board ID
 
         // Battery - Use Escape sequence
-        frame_info.append("Battery:", 0);
+        frame_info.append("Battery:");
         frame_info.append(ESC_BAT "     ", 1);
         // frame_info.append(&frame_info, esc_bat, 1);
 
         // MCU Version - Use Escape sequence
-        frame_info.append("MCUbl_ver:", 0);
+        frame_info.append("MCUbl_ver:");
         frame_info.append(ESC_MCU_BL_VER, 1);
-        frame_info.append("MCU_ver:", 0);
+        frame_info.append("MCU_ver:");
         frame_info.append(ESC_MCU_RUN_VER, 1);
 
         // Sys config present device
         if (hostPosition != BMC_POSITION)
         {
-            frame_info.append("Sys Conf. info:", 0);
+            frame_info.append("Sys Conf. info:");
 
             // Dimm info
             std::vector<std::string> data;
@@ -825,7 +738,7 @@
             {
                 for (auto& info : data)
                 {
-                    frame_info.append(info.c_str(), 1);
+                    frame_info.append(info, 1);
                 }
             }
             else
@@ -839,7 +752,7 @@
             {
                 result = "Not Found";
             }
-            frame_info.append(result.c_str(), 1);
+            frame_info.append(result, 1);
         }
 
     } // End of update frame
@@ -872,9 +785,9 @@
     if (page == 1)
     {
         // Initialize and clear frame (example initialization)
-        frame_postcode.init(FRAME_BUFF_SIZE);
+        frame_postcode.init();
         snprintf(frame_postcode.title, 32, "Extra Post Code");
-        frame_sel.overwrite = 1;
+        frame_sel.overwrite = true;
         frame_sel.max_page = 5;
 
         // Synchronously get D-Bus connection
@@ -902,7 +815,7 @@
             for (const auto& [code, extra] : postcodes)
             {
                 result = std::format("{:02x}", code);
-                frame_postcode.append(result.c_str(), 0);
+                frame_postcode.append(result);
             }
         }
         catch (const std::exception& e)
@@ -1052,9 +965,9 @@
         if (item > 0 && item <= sizeof(pwr_policy_item_map))
         {
             policy = pwr_policy_item_map[item - 1];
-            pal_set_power_restore_policy(pos, &policy, NULL);
+            pal_set_power_restore_policy(pos, &policy, nullptr);
         }
-        pal_get_chassis_status(pos, NULL, buff, &res_len);
+        pal_get_chassis_status(pos, nullptr, buff, &res_len);
         policy = (((uint8_t)buff[0]) >> 5) & 0x7;
         snprintf(panels[PANEL_POWER_POLICY].item_str[1], 32, "%cPower On",
                  policy == POWER_CFG_ON ? '*' : ' ');
@@ -1103,7 +1016,7 @@
     buffer[1] = item;
     buffer[2] = std::size(panels[cur_panel].item_str[item]);
 
-    if (buffer[2] > 0 && (buffer[2] + 3) < FRAME_PAGE_BUF_SIZE)
+    if (buffer[2] > 0 && (buffer[2] + 3u) < FRAME_PAGE_BUF_SIZE)
     {
         std::memcpy(&buffer[3], (panels[cur_panel].item_str[item]).c_str(),
                     buffer[2]);
