uploaded refactored solution