Added support for stateful closures with parameters