added refactored solution