Add unique constraint to provider/uid combos
Heavy refactoring of controllers to reduce code and increase understanding. Some refactoring of tests to avoid hitting the db.