Refactored solution.