Convert some anonymous functions to named functions so that we get better stack traces