First refactorized version