diff --git a/src/Controller/DevelController.php b/src/Controller/DevelController.php
index da65deb..5cae6f7 100644
--- a/src/Controller/DevelController.php
+++ b/src/Controller/DevelController.php
@@ -286,19 +286,28 @@ class DevelController extends ControllerBase {
    * @return \Symfony\Component\HttpFoundation\RedirectResponse
    */
   public function switchUser($name = NULL) {
-    // global $user;
+    if (isset($name) && ($account = user_load_by_name($name))) {
+      $current_user = \Drupal::currentUser();
 
-    // $module_handler = $this->moduleHandler();
-    // $session_manager = \Drupal::service('session_manager');
+      // Load an actual user so as we have a full user object available.
+      $full_current_user = User::load($current_user->id());
+      // Call logout hooks when switching from original user.
+      $module_handler = \Drupal::moduleHandler();
+      $module_handler->invokeAll('user_logout', [$full_current_user]);
 
-    if ($uid = $this->currentUser()->id()) {
-      // @todo Is this needed?
-      // user_logout();
-    }
-    if (isset($name) && $account = user_load_by_name($name)) {
-      // See https://www.drupal.org/node/218104
-      $accountSwitcher = Drupal::service('account_switcher');
-      $accountSwitcher->switchTo(new UserSession(array('uid' => $account->getId())));
+      $session_manager = \Drupal::service('session_manager');
+
+      // Regenerate the session ID to prevent against session fixation attacks.
+      $session_manager->regenerate();
+
+      // Based off masquarade module as:
+      // https://www.drupal.org/node/218104 doesn't stick and instead only
+      // keeps context until redirect.
+      $current_user->setAccount($account);
+      \Drupal::service('session')->set('uid', $account->id());
+
+      // Call all login hooks when switching to masquerading user.
+      $module_handler->invokeAll('user_login', [$account]);
 
       // Send her on her way.
       $destination = $this->getDestinationArray();
diff --git a/src/Form/SwitchUserForm.php b/src/Form/SwitchUserForm.php
index 817293a..177f334 100644
--- a/src/Form/SwitchUserForm.php
+++ b/src/Form/SwitchUserForm.php
@@ -11,6 +11,8 @@ use Drupal\Core\Access\CsrfTokenGenerator;
 use Drupal\Core\Form\FormBase;
 use Drupal\Core\Form\FormStateInterface;
 use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Core\Url;
+use Drupal\user\Entity\User;
 
 /**
  * Defines a form that allows privileged users to generate entities.
@@ -54,12 +56,18 @@ class SwitchUserForm extends FormBase {
    */
   public function buildForm(array $form, FormStateInterface $form_state) {
     $form['username'] = array(
-      '#type' => 'textfield',
+      '#type' => 'entity_autocomplete',
       '#description' => t('Enter username'),
-      '#autocomplete_route_name' => 'user.autocomplete',
+      '#target_type' => 'user',
       '#maxlength' => USERNAME_MAX_LENGTH,
       '#size' => 16,
+      '#selection_settings' => array(
+        'include_anonymous' => FALSE
+      ),
+      '#process_default_value' => FALSE,
     );
+
+
     $form['submit'] = array(
       '#type' => 'submit',
       '#value' => t('Switch'),
@@ -73,7 +81,7 @@ class SwitchUserForm extends FormBase {
    * {@inheritdoc}
    */
   public function validateForm(array &$form, FormStateInterface $form_state) {
-    if (!$account = user_load_by_name($form_state->getValue('username'))) {
+    if (!$account = User::load($form_state->getValue('username'))) {
       $form_state->setErrorByName('username', t('Username not found'));
     }
   }
@@ -82,8 +90,8 @@ class SwitchUserForm extends FormBase {
    * {@inheritdoc}
    */
   public function submitForm(array &$form, FormStateInterface $form_state) {
-    $name = $form_state->getValue('username');
-    $path = 'devel/switch/' . $name;
-    $form_state->setRedirect('devel.switch', array('name' => $name), array('query' => array( 'destination' => '', 'token' => $this->csrfTokenGenerator->get($path))));
+    $user = User::load($form_state->getValue('username'));
+    $path = 'devel/switch/' . $user->getUsername();
+    $form_state->setRedirectUrl(Url::fromRoute('devel.switch', array('name' => $user->getUsername()), array('query' => array('destination' => '<front>', 'token' => $this->csrfTokenGenerator->get($path)))));
   }
 }
diff --git a/src/Plugin/Block/DevelSwitchUser.php b/src/Plugin/Block/DevelSwitchUser.php
index 1fceb7a..6fc1d0f 100644
--- a/src/Plugin/Block/DevelSwitchUser.php
+++ b/src/Plugin/Block/DevelSwitchUser.php
@@ -166,9 +166,10 @@ class DevelSwitchUser extends BlockBase implements ContainerFactoryPluginInterfa
       $build = array(
         'devel_links' => array('#theme' => 'links', '#links' => $links),
         '#attached' => array(
-          'css' => array(
-            drupal_get_path('module', 'devel') . '/css/devel.css')
-          )
+          'library' => array(
+            'devel/devel',
+          ),
+        ),
       );
       if ($this->configuration['show_form']) {
         $build['devel_form'] = $this->formBuilder->getForm('\Drupal\devel\Form\SwitchUserForm');
@@ -204,7 +205,7 @@ class DevelSwitchUser extends BlockBase implements ContainerFactoryPluginInterfa
       $query->range(0, $list_size);
 
       if (!isset($roles[DRUPAL_AUTHENTICATED_RID])) {
-        $query->leftJoin('users_roles', 'r', 'u.uid = r.uid');
+        $query->leftJoin('user__roles', 'r', 'u.uid = r.entity_id');
         $or_condition = db_or();
         $or_condition->condition('u.uid', 1);
         if (!empty($roles)) {
@@ -230,7 +231,7 @@ class DevelSwitchUser extends BlockBase implements ContainerFactoryPluginInterfa
       $num_links = count($links);
       if ($num_links < $list_size) {
         // If we don't have enough, add distinct uids until we hit $list_size.
-        $uids = db_query_range('SELECT u.uid FROM {users} u INNER JOIN {users_field_data} ufd WHERE u.uid > 0 AND u.uid NOT IN (:uids) AND ufd.status > 0 ORDER BY ufd.access DESC', 0, $list_size - $num_links, array(':uids' => array_keys($links)))->fetchCol();
+        $uids = db_query_range('SELECT u.uid FROM {users} u INNER JOIN {users_field_data} ufd WHERE u.uid > 0 AND u.uid NOT IN (:uids[]) AND ufd.status > 0 ORDER BY ufd.access DESC', 0, $list_size - $num_links, array(':uids[]' => array_keys($links)))->fetchCol();
         $accounts = user_load_multiple($uids);
         foreach ($accounts as $account) {
           $path = 'devel/switch/' . $account->name->value;
@@ -253,7 +254,7 @@ class DevelSwitchUser extends BlockBase implements ContainerFactoryPluginInterfa
           'attributes' => array('title' => t('Caution: the anonymous user will be unable to switch back.')),
         );
         if ($this->currentUser->hasPermission('switch users')) {
-          $link['title'] = SafeMarkup::placeholder($link['title']);
+          $link['title'] = SafeMarkup::format('%title', array('%title' => $link['title']));
           $link['attributes'] = array('title' => t('This user can switch back.'));
           $link['html'] = TRUE;
         }
