Better factorization of the code