Refactored solution 45