Final Refactored Code