Extract lambda to function