Refactor model.database