added missing 'var', added closure for tables