Working version -- changed the db operations entirely.