modified debugger handlers and add common functions for safety