Fix bug with precedence of clauses in template