revised refactored solution