almost done with template parsing/balancing