Refactorization of the code