improved anonymous function handling