Cleanup and ove the debug function inside anonymous function.