Fix tbg

- fix that nested templates not solved
- add variable cycle dependency detection