updated code with watchdog in place