moved more smarts to db