Refactored code with successful compile