Tech Debt: Refactor and add tests