fixed a bug in template parsing