initial solution and refactored solution