Refactor watchdog and trace hook