Factorize duplicated code