Fix to stop warning about undefined variable
Added support for closures