Added $wpdb->prepare to escape all database queries

Also removed a ton of unnecessary global $wpdbs