4335 pull from staging

can we declare the lambda outside this function for readability?