refactored and extended repository pattern