generate as clauses only where needed

easier to read in its own class