fixed problem when parsing nested templates