move mega-closure to its own function