Some refactoring of the db and add repositories