refactored for repository pattern