Factorize code