Added implementation.

All queries are prepared.
New function create good table names (using %s in $wpdb->prepare adds single quotes, which mysql does not like)
added lookup to first site, since the table structure is slightly different