refactorized code