moved all the clauses to separate functions