Refactored Solution