Add table insertion for most tables. Clean up database access.