Refactored code to a repository approach