fix foreach callback to handle user_data