Refactored solution 10