fix infinite recursion bug