added support to pass variables into the encased anonymous function