diff --git a/domain_variable.class.inc b/domain_variable.class.inc
index f045771..44633df 100644
--- a/domain_variable.class.inc
+++ b/domain_variable.class.inc
@@ -31,7 +31,7 @@ class DomainVariableRealmController extends VariableRealmDefaultController {
    * Implementation of VariableRealmControllerInterface::getRequestKey().
    */
   public function getRequestKey() {
-    return i18n_variable_language()->language;
+    return _domain_variable_realm_key(domain_get_domain());
   }
   /**
    * Implementation of VariableRealmControllerInterface::getAllKeys().
diff --git a/domain_variable.module b/domain_variable.module
index 5bcae28..384f44f 100644
--- a/domain_variable.module
+++ b/domain_variable.module
@@ -52,8 +52,6 @@ function domain_variable_variable_realm_info() {
 function domain_variable_domain_bootstrap_full($domain) {
   // Avoid loading this for drush and update.php
   if (function_exists('drush_verify_cli') || function_exists('update_prepare_d7_bootstrap')) return;
-  // This is not the full domain array so we use domain_id here.
-  $realm_key = _domain_variable_realm_key($domain['domain_id']);
   // Handle language default variable that must be an object.
   // @todo Get rid of this weird part, store language as object.
   /*if (!empty($variables['language_default']) && !is_object($variables['language_default'])) {
@@ -66,7 +64,7 @@ function domain_variable_domain_bootstrap_full($domain) {
       unset($variables['language_default']);
     }
   }*/
-  variable_realm_initialize('domain', $realm_key);
+  module_invoke('variable_realm', 'initialize', 'domain');
 }
 
 /**
@@ -130,11 +128,21 @@ function domain_variable_get($domain_id, $variable = '', $all = FALSE, $reset =
 }
 
 /**
- * Get realm key from domain or domain_id
+ * Get realm key from domain array, machine_name or domain_id.
  */
 function _domain_variable_realm_key($domain) {
-  $domain = is_array($domain) ? $domain : domain_lookup($domain);
-  return $domain['machine_name'];
+  if (is_string($domain)) {
+    return $domain;
+  }
+  elseif (is_numeric($domain)) {
+    return domain_load_machine_name($domain);
+  }
+  elseif (is_array($domain)) {
+    return isset($domain['machine_name']) ? $domain['machine_name'] : domain_load_machine_name($domain['domain_id']);
+  }
+  else {
+    throw new InvalidArgumentException('Invalid argument value for $domain in function _domain_variable_realm_key(): ' . $domain);
+  }
 }
 
 /**
