refactor Database.insert