Refactoring repository pattern