Fix circular reasoning in free variable calculation