second version refactored