Concur, nested functions (nested anything, really) decreases readability and can sometimes make it harder to debug/troubleshoot. Would recommend extracting this function.