Perform significant refactoring

of how repos work and how they fetch data from the database.