main refactorization