using old free_vars algo again