Factor out common where clauses