Refactor database and models.