Rewrite getting departments with GCD