fixed memory errors with the closures