fixed the NPE caused by closures being cleaned before being passed into the aggregate function