diff --git a/flag.module b/flag.module
index dd7a243..0a2ecdd 100644
--- a/flag.module
+++ b/flag.module
@@ -941,7 +941,7 @@ function flag_entity_view($entity, $type, $view_mode, $langcode) {
     $entity_id = $flag->get_entity_id($entity);
     if ($flag->show_as_field) {
       $entity->content['flag-' . $flag->name] = array(
-       '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, FALSE, array(), array('needs_wrapping_element' => TRUE)),
+       '#markup' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array('needs_wrapping_element' => TRUE)),
       );
     }
   }
diff --git a/includes/flag.pages.inc b/includes/flag.pages.inc
index ce4bd5c..cfb91ba 100644
--- a/includes/flag.pages.inc
+++ b/includes/flag.pages.inc
@@ -149,7 +149,10 @@ function flag_build_javascript_info($flag, $entity_id) {
   $errors = $flag->get_errors();
   $info = array(
     'status' => TRUE,
-    'newLink' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, TRUE, $errors),
+    'newLink' => $flag->theme($flag->is_flagged($entity_id) ? 'unflag' : 'flag', $entity_id, array(
+      'after_flagging' => TRUE,
+      'errors' => $errors,
+    )),
     // Further information for the benefit of custom JavaScript event handlers:
     'flagSuccess' => !$errors,
     'contentId' => $entity_id,
diff --git a/includes/flag/flag_flag.inc b/includes/flag/flag_flag.inc
index b8b09a3..0c466a4 100644
--- a/includes/flag/flag_flag.inc
+++ b/includes/flag/flag_flag.inc
@@ -1439,22 +1439,22 @@ class flag_flag {
    *  The action the link is about to carry out, either "flag" or "unflag".
    * @param $entity_id
    *  The ID of the object to flag.
-   * @param $after_flagging = FALSE
-   *  (Optional) Set to TRUE if this flag link is being displayed as the result
-   *  of a flagging action.
-   * @param $errors = array()
-   *  An array of error messages.
    * @param $variables = array()
-   *  An array of further variables to pass to theme('flag'). For parameters
-   *  documentation, see flag.tpl.php
+   *  An array of further variables to pass to theme('flag'). For the full list
+   *  of parameters, see flag.tpl.php. Of particular interest:
+   *  - after_flagging: Set to TRUE if this flag link is being displayed as the result
+   *    of a flagging action.
+   *  - errors: An array of error messages.
    *
    * @return
    *  The HTML for the flag link.
    */
-  function theme($action, $entity_id, $after_flagging = FALSE, $errors = array(), $variables = array()) {
+  function theme($action, $entity_id, $variables = array()) {
     static $js_added = array();
     global $user;
 
+    $after_flagging = !empty($variables['after_flagging']);
+
     // If the flagging user is anonymous, set a boolean for the benefit of
     // JavaScript code. Currently, only our "anti-crawlers" mechanism uses it.
     if ($user->uid == 0 && !isset($js_added['anonymous'])) {
@@ -1492,8 +1492,6 @@ class flag_flag {
       'flag' => $this,
       'action' => $action,
       'entity_id' => $entity_id,
-      'after_flagging' => $after_flagging,
-      'errors' => $errors,
     ) + $variables);
   }
 
