fix var scope inside if issue