debug functions and closure wrap