Refactor repositories and services