move closure into its own function