[ES] Factorize code