updated database logic