Refactor Repository pattern