refactorization and cleanup