pretty extensive updates to db functions, lots of new table_exists() type stuff