Refactored solution 5.