refactored error handling in repository