diff --git a/variable_realm/variable_realm.class.inc b/variable_realm/variable_realm.class.inc
index ec252f1..52372d1 100644
--- a/variable_realm/variable_realm.class.inc
+++ b/variable_realm/variable_realm.class.inc
@@ -11,6 +11,104 @@ interface VariableRealmControllerInterface {
   /**
    * Class constructor.
    *
+   * @param $realm_name
+   *   Realm name.
+   * @param $store_class
+   *   Realm key.
+   */
+  public function __construct($realm_name, $controller_data);
+  /**
+   * Start this realm with request key.
+   */
+  public function start($realm_key = NULL);
+  /**
+   * Get title for this realm.
+   */
+  public function getTitle();
+  /**
+   * Get name for variables in this realm.
+   */
+  public function getVariableName();
+  /**
+   * Add store for realm key.
+   */
+  public function addStore($realm_key, $variables = NULL);
+  /**
+   * Get store for realm key.
+   */
+  public function getStore($realm_key);
+  /**
+   * Set store for realm key.
+   */
+  public function setStore($realm_key, $realm_store);
+  /**
+   * Get current realm key.
+   */
+  public function getKey();
+  /**
+   * Get default key for this realm.
+   */
+  public function getDefaultKey();
+  /**
+   * Get key for this page request.
+   */
+  public function getRequestKey();
+  /**
+   * Set current realm key.
+   */
+  public function setKey($realm_key);
+  /**
+   * Get all keys for this realm.
+   */
+  public function getAllKeys();
+  /**
+   * Get current realm weight.
+   */
+  public function getWeight();
+  /**
+   * Implementation of VariableRealmControllerInterface::getWeight().
+   */
+  public function getDefaultWeight();
+  /**
+   * List all current variable values.
+   */
+  public function getCurrentVariables();
+  /**
+   * Get information for this realm.
+   */
+  public function getInfo($property = NULL, $default = NULL);
+  /**
+   * Get list of variables available for this realm.
+   */
+  public function getAvailableVariables();
+  /**
+   * Get list of variables enabled for this realm.
+   */
+  public function getEnabledVariables();
+  /**
+   * Get system variable for this realm.
+   */
+  public function getRealmVariable($name, $default = NULL);
+  /**
+   * Set system variable for this realm.
+   */
+  public function setRealmVariable($name, $value);
+  /**
+   * Delete variable for all keys this realm.
+   *
+   * @param $variable_name
+   *   Variable name to delete.
+   */
+  public function deleteVariable($realm_name);
+}
+
+/**
+ * Realm Store Interface.
+ */
+interface VariableRealmStoreInterface {
+  /**
+   * Class constructor.
+   *
    * @param $realm
    *   Realm name.
    * @param $key
@@ -70,6 +168,199 @@ interface VariableRealmControllerInterface {
  * Base class, keeps static list of variables.
  */
 class VariableRealmDefaultController implements VariableRealmControllerInterface {
+  public $realm_name;
+  public $current_key;
+  public $current_weight;
+  // Controller parameters.
+  protected $controller_data;
+  // Array of variable stores indexed by realm key.
+  protected $store;
+  /**
+   * Implementation of VariableRealmControllerInterface::__construct().
+   */
+  public function __construct($realm_name, $controller_data) {
+    $this->realm_name = $realm_name;
+    $this->controller_data = $controller_data + array(
+      'store class' => 'VariableRealmDefaultStore',
+      'weight' => 0,
+    );
+    $this->current_weight = $this->getDefaultWeight();
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::start().
+   */
+  public function start($realm_key = NULL) {
+    if (!isset($this->current_key)) {
+      $this->current_key = isset($realm_key) ? $realm_key : $this->getRequestKey();
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getTitle().
+   */
+  public function getTitle() {
+    return $this->getInfo('title');
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getVariableName().
+   */
+  public function getVariableName() {
+    return $this->getInfo('variable name');
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getStore().
+   */
+  public function getStore($realm_key) {
+    if (isset($this->store[$realm_key])) {
+      return $this->store[$realm_key];
+    }
+    else {
+      return $this->addStore($realm_key);
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::addStore().
+   */
+  public function addStore($realm_key, $variables = NULL) {
+    $store = $this->createStore($realm_key, $variables);
+    $this->setStore($realm_key, $store);
+    return $store;
+  }
+  /**
+   * Create Store for key.
+   */
+  protected function createStore($realm_key, $variables = NULL) {
+    $class = class_exists($this->controller_data['store class']) ? $this->controller_data['store class'] : 'VariableRealmDefaultStore';
+    return new $class($this->realm_name, $realm_key, $variables);
+  }
+  /**
+   * Set store for realm key.
+   */
+  public function setStore($realm_key, $realm_store) {
+    $this->store[$realm_key] = $realm_store;
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::setKey().
+   */
+  public function setKey($realm_key) {
+    $this->current_key = $realm_key;
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getKey().
+   */
+  public function getKey() {
+    return isset($this->current_key) ? $this->current_key : FALSE;
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getAllKeys().
+   */
+  public function getAllKeys() {
+    if ($function = $this->getInfo('keys callback')) {
+      return $function($this->realm_name, $this->getInfo());
+    }
+    else {
+      return $this->getInfo('keys');
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getDefaultKey().
+   */
+  public function getDefaultKey() {
+    return $this->getInfo('default key', FALSE);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getRequestKey().
+   */
+  public function getRequestKey() {
+    return FALSE;
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getWeight().
+   */
+  public function getWeight() {
+    return isset($this->current_weight) ? $this->current_weight : $this->controller_data['weight'];
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getWeight().
+   */
+  public function getDefaultWeight() {
+    return $this->getRealmVariable('weight', $this->controller_data['weight']);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getCurrentVariables().
+   */
+  public function getCurrentVariables() {
+    if ($key = $this->getKey()) {
+      return $this->getStore($key)->variable_list();
+    }
+    else {
+      return array();
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getAvailableVariables().
+   */
+  public function getAvailableVariables() {
+    if ($options = $this->getInfo('options')) {
+      return $options;
+    }
+    else {
+      // Defaults to all available variables.
+      return array_keys(variable_get_info());
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getEnabledVariables().
+   */
+  public function getEnabledVariables() {
+    if ($function = $this->getInfo('list callback')) {
+      return $function($this->realm_name, $this->getInfo());
+    }
+    elseif ($this->getInfo('select')) {
+      return $this->getRealmVariable('list', array());
+    }
+    else {
+      // If the variable is not set it will default to all variables
+      return $this->getAvailableVariables();
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getInfo().
+   */
+  public function getInfo($property = NULL, $default = NULL) {
+    $info = variable_realm_info($this->realm_name);
+    if ($property) {
+      return isset($info[$property]) ? $info[$property] : $default;
+    }
+    else {
+      return $info;
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getRealmVariable().
+   */
+  public function getRealmVariable($name, $default = NULL) {
+    return variable_get('variable_realm_' . $name . '_' . $this->realm_name, $default);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::setRealmVariable().
+   */
+  public function setRealmVariable($name, $value) {
+    variable_realm_global_set('variable_realm_' . $name . '_' . $this->realm_name, $value);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::deleteVariable().
+   */
+  public function deleteVariable($variable_name) {
+    foreach ($this->getAllKeys() as $key) {
+      variable_realm_del($this->realm_name, $key, $variable_name, FALSE);
+    }
+  }
+}
+
+/**
+ * Base class, keeps static list of variables.
+ */
+class VariableRealmDefaultStore implements VariableRealmStoreInterface {
   public $realm;
   public $key;
   protected $variables;
@@ -142,7 +433,7 @@ class VariableRealmDefaultController implements VariableRealmControllerInterface
 /**
  * Controller for default system variables.
  */
-class VariableRealmGlobal extends VariableRealmDefaultController {
+class VariableRealmGlobal extends VariableRealmDefaultStore {
   /**
    * Initialize variables.
    */
diff --git a/variable_realm/variable_realm.features.inc b/variable_realm/variable_realm.features.inc
index 88d2704..c612f75 100644
--- a/variable_realm/variable_realm.features.inc
+++ b/variable_realm/variable_realm.features.inc
@@ -10,12 +10,13 @@
  */
 function variable_realm_features_export_options() {
   foreach (variable_realm_info() as $name => $realm) {
-    $realm_keys = variable_realm_keys($name);
+    $controller = variable_realm_controller($name);
+    $realm_keys = $controller->getAllKeys();
     if (count($realm_keys) > 1) {
-      $options[$name] = $realm['title'] . ': ' . t('all');
+      $options[$name] = $controller->getTitle() . ': ' . t('all');
     }
     foreach ($realm_keys as $key => $title) {
-      $options[$name . ':' . $key] = $realm['title'] . ': ' . $title;
+      $options[$name . ':' . $key] = $controller->getTitle() . ': ' . $title;
     }
   }
   return $options;
diff --git a/variable_realm/variable_realm.form.inc b/variable_realm/variable_realm.form.inc
index 07cb1f2..cb5facc 100644
--- a/variable_realm/variable_realm.form.inc
+++ b/variable_realm/variable_realm.form.inc
@@ -8,8 +8,9 @@
  * Select variables for realm.
  */
 function variable_realm_select_variables_form($form, &$form_state, $realm_name) {
-  $current = variable_realm_get_variable_list($realm_name);
-  $optional = variable_realm_get_variable_options($realm_name);
+  $controller = variable_realm_controller($realm_name);
+  $current = $controller->getEnabledVariables();
+  $optional = $controller->getAvailableVariables();
   // The final list will be the sum of both lists. We may have unknown variables
   // we want to preserve.
   $list = array_unique(array_merge($optional, $current));
@@ -39,7 +40,8 @@ function variable_realm_select_variables_form($form, &$form_state, $realm_name)
 function variable_realm_select_variables_form_submit($form, &$form_state) {
   // Get realm name and current list of variables.
   $realm_name = $form_state['values']['realm_name'];
-  $old_variables = variable_realm_get_variable_list($realm_name);
+  $controller = variable_realm_controller($realm_name);
+  $old_variables = $controller->getEnabledVariables();
   // Get main variable names
   $variables = $form_state['values']['variables'];
   $variables = array_keys(array_filter($variables));
@@ -50,13 +52,13 @@ function variable_realm_select_variables_form_submit($form, &$form_state) {
   // Hook for modules to alter this variable list.
   drupal_alter('variable_realm_variable_list', $variables, $realm_name);
   // And save the list to a variable.
-  variable_set('variable_realm_list_' . $realm_name, $variables);
+  $controller->setRealmVariable('list', $variables);
   // Spawn multiple variables and translate into actual variables
   $new_list = variable_children($variables);
   // Delete variables from realm that are not in the new list.
   $old_list = variable_children($old_variables);
   foreach (array_diff($old_list, $new_list) as $name) {
-    variable_realm_delete_variable($realm_name, $name);
+    $controller->deleteVariable($name);
     drupal_set_message(t('Deleted existing values of %name from realm variables.', array('%name' => $name)));
   }
 }
@@ -65,11 +67,11 @@ function variable_realm_select_variables_form_submit($form, &$form_state) {
  * Edit variables for realm.
  */
 function variable_realm_edit_variables_form($form, &$form_state, $realm_name, $realm_key) {
-  $realm_info = variable_realm_info($realm_name);
+  $controller = variable_realm_controller($realm_name);
   $form['realm_name'] = array('#type' => 'value', '#value' => $realm_name);
   $form['realm_key'] = array('#type' => 'value', '#value' => $realm_key);
   $options['realm'] = variable_realm($realm_name, $realm_key);
-  if ($variable_list = variable_realm_get_variable_list($realm_name)) {
+  if ($variable_list = $controller->getEnabledVariables()) {
     // Group variables by variable group for vertical tabls
     $group_list = array();
     foreach ($variable_list as $variable_name) {
@@ -95,7 +97,7 @@ function variable_realm_edit_variables_form($form, &$form_state, $realm_name, $r
     $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
   }
   else {
-    $form['message']['#markup'] = '<h3>' . t('No variables have been selected as %realm_name specific.', array('%realm_name' => $realm_info['title'])) . '</h3>';
+    $form['message']['#markup'] = '<h3>' . t('No variables have been selected as %realm_name specific.', array('%realm_name' => $controller->getTitle())) . '</h3>';
   }
   if (!empty($realm_info['select path'])) {
     $form['select']['#markup'] = t('To select variables to be configured, see <a href="!select-url">%realm_name variable settings</a>.', array(
@@ -130,17 +132,17 @@ function variable_realm_edit_variables_form_submit($form, &$form_state) {
 function variable_realm_form_key_selector($realm_name, $current_key) {
   $element_name = VARIABLE_REALM_FORM_SWITCHER . $realm_name;
   $query_name = 'variable_realm_' . $realm_name . '_key';
-  $realm_info = variable_realm_info($realm_name);
+  $controller = variable_realm_controller($realm_name);
   $form[$element_name] = array(
     '#type' => 'fieldset',
-    '#title' => t('There are %name variables in this form', array('%name' => $realm_info['variable name'])),
+    '#title' => t('There are %name variables in this form', array('%name' => $controller->getVariableName())),
     '#weight' => -100,
-    '#description' => t('Check you are editing the variables for the right %realm value or select the desired %realm.', array('%realm' => $realm_info['title'])),
+    '#description' => t('Check you are editing the variables for the right %realm value or select the desired %realm.', array('%realm' => $controller->getTitle())),
   );
   // Replace only this element on current query string, there may be others.
   $current_query = $_GET;
   unset($current_query['q']);
-  foreach (variable_realm_keys($realm_name) as $realm_key => $key_name) {
+  foreach ($controller->getAllKeys() as $realm_key => $key_name) {
     $query[VARIABLE_REALM_QUERY_STRING . $realm_name] = $realm_key;
     $link =  l($key_name, $_GET['q'], array('query' => $query + $current_query));
     $items[] = $current_key == $realm_key ? '<strong>' . $link . '</strong>' : $link;
@@ -166,8 +168,7 @@ function variable_realm_form_key_current($realm_name, $default_key = NULL) {
     return $default_key;
   }
   else {
-    $realm_info = variable_realm_info($realm_name);
-    return $realm_info['default key'];
+    variable_realm_controller($realm_name)->getDefaultKey();
   }
 }
 
@@ -229,7 +230,7 @@ function _variable_realm_variable_settings_form_conflict($variable) {
 function variable_realm_variable_settings_form_submit($form, &$form_state) {
   $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : '';
   foreach ($form['#realm_keys'] as $realm_name => $realm_key) {
-    $realm_info = variable_realm_info($realm_name);
+    $realm_controller = variable_realm_controller($realm_name);
     //$language = i18n_language($form_state['values']['i18n_variable_language']);
     //unset($form_state['values']['i18n_variable_language']);
     $variables = array_keys($form['#realm_variables'][$realm_name]);
@@ -246,7 +247,7 @@ function variable_realm_variable_settings_form_submit($form, &$form_state) {
           variable_realm_set($realm_name, $realm_key, $variable_name, $value);
         }
         // If current is not default realm key, we don't set any global variable (without realm)
-        if ($realm_key != $realm_info['default key']) {
+        if ($realm_key != $realm_controller->getDefaultKey()) {
           unset($form_state['values'][$variable_name]);
         }
       }
@@ -282,9 +283,8 @@ function variable_realm_variable_theme_form_submit($form, &$form_state) {
  */
 function _variable_realm_variable_settings_form_list() {
   $list = array();
-  foreach (array_keys(variable_realm_list()) as $realm_name) {
-    $realm_info = variable_realm_info($realm_name);
-    if (!empty($realm_info['form settings']) && ($realm_list = variable_realm_get_variable_list($realm_name))) {
+  foreach (variable_realm_controller() as $realm_name => $controller) {
+    if ($controller->getInfo('form settings') && ($realm_list = $controller->getEnabledVariables())) {
       // Remove from previous realms with lower weight.
       foreach ($list as $name => $variables) {
         $list[$name] = array_diff($variables, $realm_list);
diff --git a/variable_realm/variable_realm.module b/variable_realm/variable_realm.module
index a53db2c..de67464 100644
--- a/variable_realm/variable_realm.module
+++ b/variable_realm/variable_realm.module
@@ -15,6 +15,7 @@ define('VARIABLE_REALM_FORM_SWITCHER', 'variable_realm_selector_');
  * We set variable realm and language code as early as possible in the page request.
  */
 function variable_realm_boot() {
+  // Initialize global default variables but don't rebuild variable list yet.
   variable_realm_status('global', 'default');
 }
 
@@ -33,6 +34,18 @@ function variable_realm_init() {
 }
 
 /**
+ * Initialize realm and set key depending on request.
+ *
+ * @param $realm_name
+ *   Variable realm name.
+ * @param $realm_key
+ *   Optional key to be set when we don't have other key.
+ */
+function variable_realm_start($realm_name, $realm_key = NULL) {
+  variable_realm_controller($realm_name)->start($realm_key);
+}
+
+/**
  * Get realm parameters from query string.
  */
 function variable_realm_params($realm_name = NULL) {
@@ -91,56 +104,31 @@ function variable_realm_info($realm = NULL) {
 }
 
 /**
- * Get list of all available realms ordered by default weight.
+ * Get list of all available realm names ordered by default weight.
  */
 function variable_realm_list() {
-  $list = array();
-  foreach (variable_realm_info() as $name => $info) {
-    $list[$name] = $info['title'];
-    uksort($list, '_variable_realm_sort');
-  }
-  return $list;
+  return _variable_realm_invoke(variable_realm_all(), 'getTitle');
 }
 
 /**
- * Get keys for realm.
+ * Get all available realm controllers ordered by default weight.
  */
-function variable_realm_keys($realm) {
-  $info = variable_realm_info($realm);
-  if (!empty($info['keys callback'])) {
-    $function = $info['keys callback'];
-    return $function($realm, $info);
-  }
-  else {
-    return isset($info['keys']) ? $info['keys'] : array();
+function variable_realm_all() {
+  $list = array();
+  foreach (array_keys(variable_realm_info()) as $name) {
+    $list[$name] = variable_realm_controller($name);
+    usort($list, '_variable_realm_sort_default');
   }
+  return $list;
 }
 
 /**
- * Get options (allowed variables) for realm.
+ * Get keys for realm.
  */
-function variable_realm_get_variable_options($realm_name) {
-  $info = variable_realm_info($realm_name);
-  return !empty($info['options']) ? $info['options'] : array_keys(variable_get_info());
+function variable_realm_keys($realm_name) {
+  return variable_realm_controller($realm_name)->getAllKeys();
 }
 
-/**
- * Get list of variable names that may be set for this realm.
- */
-function variable_realm_get_variable_list($realm_name) {
-  $info = variable_realm_info($realm_name);
-  if (!empty($info['list callback'])) {
-    $function = $info['list callback'];
-    return $function($realm_name, $info);
-  }
-  elseif (!empty($info['select'])) {
-    return variable_get('variable_realm_list_' . $realm_name, array());
-  }
-  else {
-    // If the variable is not set it will default to all variables
-    return variable_realm_get_variable_options($realm_name);
-  }
-}
 
 /**
  * Implements hook_variable_realm_controller().
@@ -148,7 +136,8 @@ function variable_realm_get_variable_list($realm_name) {
 function variable_realm_variable_realm_controller() {
   $realm['global'] = array(
     'weight' => 0,
-    'class' => 'VariableRealmGlobal',
+    'controller class' => 'VariableRealmDefaultController',
+    'store class' => 'VariableRealmGlobal',
   );
   return $realm;
 }
@@ -156,13 +145,13 @@ function variable_realm_variable_realm_controller() {
 /**
  * Get class and weight information for variable realm.
  */
-function variable_realm_controller($realm = NULL) {
+function variable_realm_controller_info($realm = NULL) {
   $data = &drupal_static(__FUNCTION__);
   if (!isset($keys)) {
     $data = module_invoke_all('variable_realm_controller');
   }
   if ($realm) {
-    return isset($data[$realm]) ? $data[$realm] : NULL;
+    return isset($data[$realm]) ? $data[$realm] : array();
   }
   else {
     return $data;
@@ -170,37 +159,7 @@ function variable_realm_controller($realm = NULL) {
 }
 
 /**
- * Create realm controller object.
- */
-function _variable_realm_controller($realm, $key, $variables = NULL) {
-  $info = variable_realm_controller($realm);
-  $class = isset($info['class']) ? $info['class'] : 'VariableRealmDefaultController';
-  // Set realm weight if not set before.
-  variable_realm_weight($realm, NULL, _variable_realm_weight($realm));
-  return new $class($realm, $key, $variables);
-}
-
-/**
- * Get default weight for realm.
- *
- * Realm weight is defined in hook_variable_realm_controller() and can be overridden
- * by a variable named 'variable_realm_weight_[realm_name]'.
- */
-function _variable_realm_weight($realm_name) {
-  $info = variable_realm_controller($realm_name);
-  $weight = $info && isset($info['weight']) ? $info['weight'] : 0;
-  return variable_get('variable_realm_weight_' . $realm_name, $weight);
-}
-
-/**
- * Order realm names by weight.
- */
-function _variable_realm_sort($a, $b) {
-  return _variable_realm_weight($a) - _variable_realm_weight($b);
-}
-
-/**
- * Get variable realm controller.
+ * Get variable realm store.
  *
  * The first time this function is invoked we initialize the realm system
  * and store global variables in the global/default realm.
@@ -213,33 +172,30 @@ function _variable_realm_sort($a, $b) {
  * @return VariableRealmControllerInterface
  */
 function variable_realm($realm, $key) {
+  return variable_realm_controller($realm)->getStore($key);
+}
+
+/**
+ * Get variable realm controller or create it if not defined.
+ */
+function variable_realm_controller($realm_name = NULL) {
   static $drupal_static_fast;
   if (!isset($drupal_static_fast)) {
     $drupal_static_fast['realm'] = &drupal_static(__FUNCTION__);
-    $drupal_static_fast['realm']['global']['default'] = _variable_realm_controller('global', 'default', $GLOBALS['conf']);
+    $drupal_static_fast['realm']['global'] = _variable_realm_controller('global');
+    $drupal_static_fast['realm']['global']->addStore('default', $GLOBALS['conf']);
   }
   $variable_realm = &$drupal_static_fast['realm'];
 
-  if (!isset($variable_realm[$realm][$key])) {
-    $variable_realm[$realm][$key] = _variable_realm_controller($realm, $key);
-  }
-  return $variable_realm[$realm][$key];
-}
-
-/**
- * Build current realm.
- *
- * Buids an array of variables for the current realm with higher weights overriding
- * lower weights.
- */
-function variable_realm_build() {
-  $variables = array();
-  foreach (variable_realm_current() as $realm => $key) {
-    if ($key !== FALSE && ($values = variable_realm($realm, $key)->variable_list())) {
-      $variables = array_merge($variables, $values);
+  if ($realm_name) {
+    if (!isset($variable_realm[$realm_name])) {
+      $variable_realm[$realm_name] = _variable_realm_controller($realm_name);
     }
+    return $variable_realm[$realm_name];
+  }
+  else {
+    return $variable_realm;
   }
-  return $variables;
 }
 
 /**
@@ -315,17 +271,39 @@ function variable_realm_delete_variable($realm_name, $variable_name, $rebuild =
 }
 
 /**
+ * Get current realm controllers ordered by weight, only for realms that are set.
+ */
+function variable_realm_current() {
+  $current = variable_realm_controller();
+  $active = array_filter($current, '_variable_realm_status');
+  uasort($active, '_variable_realm_sort_current');
+  return $active;
+}
+
+/**
+ * Check whether a realm is defined.
+ */
+function variable_realm_defined($realm_name) {
+  $controllers = variable_realm_controller();
+  return !empty($controllers[$realm_name]);
+}
+
+/**
+ * Get current realm values ordered by weights, only realms that are set.
+ *
+ * @return array
+ *   Ordered array of name => key pairs.
+ */
+function variable_realm_current_keys() {
+  return array_map('_variable_realm_status', variable_realm_current());
+}
+
+/**
  * Get current realm values ordered by weights.
  *
  * @return array
  *   Ordered array of name => value pairs, only realms that are set.
  */
-function variable_realm_current() {
-  $realms = variable_realm_weight();
-  $current = array_combine($realms, $realms);
-  // Filter the result so we don't return unset realms
-  return array_filter(array_map('variable_realm_status', $current));
-}
 
 /**
  * Get original global variable
@@ -357,20 +335,12 @@ function variable_realm_global_set($name, $value = NULL, $rebuild = TRUE) {
  *   Optional realm value to set a status for this realm.
  *   FALSE to disable this realm.
  */
-function variable_realm_status($realm = NULL, $key = NULL) {
-  $status = &drupal_static(__FUNCTION__, array());
-  if ($realm && isset($key)) {
-    // Make sure the realm is created.
-    variable_realm($realm, $key);
-    // Set current realm key.
-    $status[$realm] = $key;
-  }
-  if ($realm) {
-    return isset($status[$realm]) ? $status[$realm] : NULL;
-  }
-  else {
-    return $status;
+function variable_realm_status($realm, $key = NULL) {
+  $realm_controller = variable_realm_controller($realm);
+  if (isset($key)) {
+    $realm_controller->setKey($key);
   }
+  return $realm_controller->getKey();
 }
 
 /**
@@ -404,19 +374,15 @@ function variable_realm_switch($realm, $key) {
  *   Optional realm name
  * @param $weight
  *   Optional numeric value for realm weight.
- * @param $default
- *   Default weight to set if no $weight is set.
- * @return array()
- *   Ordered realm names.
- */
-function variable_realm_weight($realm = NULL, $weight = NULL, $default = 10) {
-  $current = &drupal_static(__FUNCTION__, array());
-  if ($realm && !isset($current[$realm]) || isset($weight)) {
-    $current[$realm] = isset($weight) ? $weight : $default;
-    asort($current);
+ * @return integer
+ *   Current realm weight
+ */
+function variable_realm_weight($realm, $weight = NULL) {
+  $realm_controller = variable_realm_controller($realm);
+  if (isset($weight)) {
+    $realm_controller->setWeight($weight);
   }
-  // This will always return ordered keys
-  return array_keys($current);
+  return $realm_controller->getWeight();
 }
 
 /**
@@ -431,7 +397,7 @@ function variable_realm_weight($realm = NULL, $weight = NULL, $default = 10) {
  */
 function variable_realm_rebuild($realm = NULL, $key = NULL) {
   if (!$realm || !$key || variable_realm_status($realm) == $key) {
-    $GLOBALS['conf'] = variable_realm_build();
+    $GLOBALS['conf'] = _variable_realm_build();
   }
 }
 
@@ -480,3 +446,66 @@ function variable_realm_features_api() {
   return $components;
 }
 
+/**
+ * Build current realm.
+ *
+ * Buids an array of variables for the current realm with higher weights overriding
+ * lower weights.
+ */
+function _variable_realm_build() {
+  $variables = array();
+  foreach (variable_realm_current() as $realm_controller) {
+    if ($values = $realm_controller->getCurrentVariables()) {
+      $variables = array_merge($variables, $values);
+    }
+  }
+  return $variables;
+}
+
+/**
+ * Invoke method on a list of objects.
+ */
+function _variable_realm_invoke($list, $method) {
+  $result = array();
+  foreach ($list as $index => $object) {
+    $result[$index] = $object->$method();
+  }
+  return $result;
+}
+
+/**
+ * Create realm controller object.
+ */
+function _variable_realm_controller($realm_name) {
+  $info = variable_realm_controller_info($realm_name);
+  $class = isset($info['controller class']) && class_exists($info['controller class']) ? $info['controller class'] : 'VariableRealmDefaultController';
+  return new $class($realm_name, $info);
+}
+
+/**
+ * Get current weight for realm controller.
+ */
+function _variable_realm_weight($realm_controller) {
+  return $realm_controller->getWeight();
+}
+
+/**
+ * Order realms by default weight.
+ */
+function _variable_realm_sort_default($a, $b) {
+  return $a->getDefaultWeight() - $b->getDefaultWeight();
+}
+
+/**
+ * Order realms by current weight.
+ */
+function _variable_realm_sort_current($a, $b) {
+  return $a->getWeight() - $b->getWeight();
+}
+
+/**
+ * Get status (current key) for realm controller.
+ */
+function _variable_realm_status($realm_controller) {
+  return $realm_controller->getKey();
+}
diff --git a/variable_realm_admin/variable_realm_admin.pages.inc b/variable_realm_admin/variable_realm_admin.pages.inc
index f0a5018..0e6e5a9 100644
--- a/variable_realm_admin/variable_realm_admin.pages.inc
+++ b/variable_realm_admin/variable_realm_admin.pages.inc
@@ -45,23 +45,23 @@ function variable_realm_admin_realm_overview($form, $form_state) {
  * Lists available realms.
  */
 function variable_realm_admin_realm_info($realm_name) {
-  $info = variable_realm_info($realm_name);
+  $controller = variable_realm_controller($realm_name);
   $build['title'] = array(
     '#type' => 'item',
     '#title' => t('Name'),
-    '#markup' => $info['title'],
+    '#markup' => $controller->getTitle(),
   );
   $build['keys'] = array(
     '#theme' => 'item_list',
     '#title' => t('Keys'),
-    '#items' => variable_realm_keys($realm_name),
+    '#items' => $controller->getAllKeys(),
   );
   $build['variables'] = array(
     '#theme' => 'item_list',
     '#title' => t('Variables'),
-    '#items' => variable_realm_get_variable_list($realm_name),
+    '#items' => $controller->getEnabledVariables(),
   );
-  if (!empty($info['select'])) {
+  if ($controller->getInfo('select')) {
     $build['options'] = array(
       '#theme' => 'item_list',
       '#title' => t('Options'),
diff --git a/variable_realm_union/variable_realm_union.class.inc b/variable_realm_union/variable_realm_union.class.inc
new file mode 100644
index 0000000..4e173af
--- /dev/null
+++ b/variable_realm_union/variable_realm_union.class.inc
@@ -0,0 +1,119 @@
+<?php
+/**
+ * @file
+ * Classes for Realm Union.
+ */
+
+/**
+ * Default Realm Union class
+ */
+class VariableRealmUnionController extends VariableRealmDefaultController {
+  protected $union_realms;
+  /**
+   * Implementation of VariableRealmControllerInterface::__construct().
+   */
+  public function __construct($realm_name, $controller_data) {
+    parent::__construct($realm_name, $controller_data);
+    // Get / create realm controllers for each of the union realms.
+    foreach ($controller_data['union'] as $realm_name) {
+      $this->union_realms[$realm_name] = variable_realm_controller($realm_name);
+    }
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getKey().
+   */
+  public function getKey() {
+    $keys = $this->invokeRealms('getKey');
+    return $this->buildUnionKey($keys);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getAllKeys().
+   */
+  public function getAllKeys() {
+    $all_realm_keys = $this->invokeRealms('getAllKeys');
+    // First build all combinations of realm keys.
+    $combine = array(array('keys' => array(), 'names' => array()));
+    foreach ($all_realm_keys as $realm => $realm_keys) {
+      $new_combine = array();
+      foreach ($combine as $index => $data) {
+        foreach ($realm_keys as $new_key => $new_name) {
+          $keys = $data['keys'];
+          $names = $data['names'];
+          $keys[$realm] = $new_key;
+          $names[$realm] = $new_name;
+          $new_combine[] = array('keys' => $keys, 'names' => $names);
+        }
+      }
+      $combine = $new_combine;
+    }
+    // Now build all realm keys for the combinations.
+    $keys = array();
+    foreach ($combine as $data) {
+      $key = $this->buidUnionKey($data['keys']);
+      $name = $this->buildUnionName($data['names']);
+      $keys[$key] = $name;
+    }
+    return $keys;
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getDefaultKey().
+   */
+  public function getDefaultKey() {
+    $keys = $this->invokeRealms('getDefaultKey');
+    return $this->buildUnionKey($keys);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getRequestKey().
+   */
+  public function getRequestKey() {
+    $keys = $this->invokeRealms('getRequestKey');
+    return $this->buildUnionKey($keys);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getEnabledVariables().
+   */
+  public function getAvailableVariables() {
+    $variables = $this->invokeRealms('getAvailableVariables');
+    return call_user_func_array('array_intersect', $variables);
+  }
+  /**
+   * Implementation of VariableRealmControllerInterface::getEnabledVariables().
+   */
+  public function getEnabledVariables() {
+    $variables = $this->invokeRealms('getEnabledVariables');
+    return call_user_func_array('array_intersect', $variables);
+  }
+
+  /**
+   * Get union realms controllers.
+   */
+  protected function getRealms() {
+    return $this->union_realms;
+  }
+  /**
+   * Invoke function on all realms.
+   */
+  protected function invokeRealms($method) {
+    return _variable_realm_invoke($this->getRealms(), $method);
+  }
+  /**
+   * Build key from union realm keys.
+   */
+  protected static function buildUnionKey($keys) {
+    if (in_array(FALSE, $keys, TRUE)) {
+      return FALSE;
+    }
+    else {
+      // Make sure values are in correct order
+      ksort($keys);
+      // implode values
+      return implode(':', $keys);
+    }
+  }
+  /**
+   * Build key name from union realm key names.
+   */
+  protected static function buildUnionName($names) {
+    return implode(', ', $names);
+  }
+}
diff --git a/variable_realm_union/variable_realm_union.info b/variable_realm_union/variable_realm_union.info
index 16a177f..5a7c4fa 100644
--- a/variable_realm_union/variable_realm_union.info
+++ b/variable_realm_union/variable_realm_union.info
@@ -5,3 +5,5 @@ dependencies[] = variable
 dependencies[] = variable_realm
 core = 7.x
 
+files[] = variable_realm_union.class.inc
+
diff --git a/variable_realm_union/variable_realm_union.module b/variable_realm_union/variable_realm_union.module
index edf0ef6..ca117e0 100644
--- a/variable_realm_union/variable_realm_union.module
+++ b/variable_realm_union/variable_realm_union.module
@@ -16,7 +16,7 @@
  */
 function variable_realm_union() {
   $list = array();
-  foreach (variable_realm_controller() as $realm => $data) {
+  foreach (variable_realm_controller_info() as $realm => $data) {
     if (!empty($data['union'])) {
       $list[$realm] = $data['union'];
     }
@@ -33,43 +33,21 @@ function variable_realm_union() {
 function variable_realm_union_boot() {
 }
 
-/**
- * Constructs a combined key by concatenating given values separated by a
- * colon. Before the key is generated, the $values array is sorted
- * alphabetically by the array keys.
- *
- * @param $realm
- *   The variable realm (union).
- * @param $values
- *   The individual realm values in form of [name => value].
- */
-function variable_realm_union_build_key($realm, $values) {
-  // Make sure values are in correct order
-  ksort($values);
-
-  // implode values
-  return implode(':', $values);
-}
-
-/**
- * Build name for combined keys.
- */
-function variable_realm_union_build_name($realm, $names) {
-  return implode(', ', $names);
-}
 
 /**
  * Implements hook_variable_realm_switch().
  */
 function variable_realm_union_variable_realm_switch($realm, $key) {
   // Current realm values
-  $current_realms = variable_realm_current();
+  $current_keys = variable_realm_current_keys();
   foreach (variable_realm_union() as $realm_name => $union_realms) {
-    if ($realm_key = _variable_realm_union_find_key($realm_name, $union_realms, $current_realms)) {
-      variable_realm_switch($realm_name, $realm_key);
-    }
-    else {
-      variable_realm_switch($realm_name, FALSE);
+    if (variable_realm_defined($realm_name)) {
+      if ($realm_key = _variable_realm_union_find_key($realm_name, $union_realms, $current_keys)) {
+        variable_realm_switch($realm_name, $realm_key);
+      }
+      else {
+        variable_realm_switch($realm_name, FALSE);
+      }
     }
   }
 }
@@ -79,7 +57,7 @@ function variable_realm_union_variable_realm_switch($realm, $key) {
  */
 function variable_realm_union_variable_realm_params_alter(&$realm_params) {
   foreach (variable_realm_union() as $realm_name => $union_realms) {
-    if ($realm_key = _variable_realm_union_find_key($realm_name, $union_realms, $realm_params)) {
+    if (variable_realm_defined($realm_name) && $realm_key = _variable_realm_union_find_key($realm_name, $union_realms, $realm_params)) {
       $realm_params[$realm_name] = $realm_keys;
     }
   }
@@ -98,6 +76,6 @@ function _variable_realm_union_find_key($realm_name, $union_realms, $current_key
       $keys[$realm] = $current_keys[$realm];
     }
   }
-  return variable_realm_union_build_key($realm_name, $keys);
+  return variable_realm_controller($realm_name)->buildUnionKey($keys);
 }
 
diff --git a/variable_realm_union/variable_realm_union.variable.inc b/variable_realm_union/variable_realm_union.variable.inc
index e750ca9..eb69e0c 100644
--- a/variable_realm_union/variable_realm_union.variable.inc
+++ b/variable_realm_union/variable_realm_union.variable.inc
@@ -5,61 +5,6 @@
  */
 
 /**
- * Implements hook_variable_realm_info_alter();
- */
-function variable_realm_union_variable_realm_info_alter(&$realms) {
-  $union_realms = variable_realm_union();
-  foreach ($realms as $realm_name => &$realm_info) {
-    if (isset($union_realms[$realm_name])) {
-      $realm_info += array(
-        'keys callback' => '_variable_realm_union_realm_keys',
-        'list callback' => '_variable_realm_union_variable_list',
-      );
-    }
-  }
-}
-
-/**
- * Produce keys for union realm.
- */
-function _variable_realm_union_realm_keys($realm_name, $realm_info) {
-  $union = array_combine($realm_info['union'], $realm_info['union']);
-  $all_realm_keys = array_map('variable_realm_keys', $union);
-  // First build all combinations of realm keys.
-  $combine = array(array('keys' => array(), 'names' => array()));
-  foreach ($all_realm_keys as $realm => $realm_keys) {
-    $new_combine = array();
-    foreach ($combine as $index => $data) {
-      foreach ($realm_keys as $new_key => $new_name) {
-        $keys = $data['keys'];
-        $names = $data['names'];
-        $keys[$realm] = $new_key;
-        $names[$realm] = $new_name;
-        $new_combine[] = array('keys' => $keys, 'names' => $names);
-      }
-    }
-    $combine = $new_combine;
-  }
-  // Now build all realm keys for the combinations.
-  $keys = array();
-  foreach ($combine as $data) {
-    $key = variable_realm_union_build_key($realm_name, $data['keys']);
-    $name = variable_realm_union_build_name($realm_name, $data['names']);
-    $keys[$key] = $name;
-  }
-  return $keys;
-}
-
-/**
- * Produce keys for union realm.
- */
-function _variable_realm_union_variable_list($realm_name, $realm_info) {
-  $union = array_combine($realm_info['union'], $realm_info['union']);
-  $variables = array_map('variable_realm_get_variable_list', $union);
-  return call_user_func_array('array_intersect', $variables);
-}
-
-/**
  * Implements hook_variable_settings_form_alter().
  *
  * Make sure realm switchers are added for all realms in the union.
diff --git a/variable_store/variable_store.class.inc b/variable_store/variable_store.class.inc
index 5099f72..965af85 100644
--- a/variable_store/variable_store.class.inc
+++ b/variable_store/variable_store.class.inc
@@ -4,7 +4,7 @@
  * Variable realm controller
  */
 
-class VariableStoreRealmController extends VariableRealmDefaultController {
+class VariableStoreRealmStore extends VariableRealmDefaultStore {
   /**
    * Initialize realm.
    */
