diff --git a/flag.module b/flag.module
index a1b45ea..6476ed0 100644
--- a/flag.module
+++ b/flag.module
@@ -1601,10 +1601,6 @@ function template_preprocess_flag(&$variables) {
     $variables['message_text'] = '';
   }
 
-  $variables['flag_wrapper_classes'] = implode(' ', $variables['flag_wrapper_classes_array']);
-  $variables['flag_classes'] = implode(' ', $variables['flag_classes_array']);
-  $variables['message_classes'] = join(' ', $variables['message_classes_array']);
-
   // Backward compatibility: The following section preserves some deprecated
   // variables either to make old flag.tpl.php files continue to work, or to
   // prevent PHP from generating E_NOTICEs there. @todo: Remove these sometime.
@@ -1613,6 +1609,18 @@ function template_preprocess_flag(&$variables) {
 }
 
 /**
+ * A process function for our theme('flag'). This converts class arrays to
+ * strings.
+ *
+ * See 'flag.tpl.php' for their documentation.
+ */
+function template_process_flag(&$variables) {
+  $variables['flag_wrapper_classes'] = implode(' ', $variables['flag_wrapper_classes_array']);
+  $variables['flag_classes'] = implode(' ', $variables['flag_classes_array']);
+  $variables['message_classes'] = join(' ', $variables['message_classes_array']);
+}
+
+/**
  * Return an array of flag names keyed by fid.
  */
 function _flag_get_flag_names() {
