diff --git a/term_permissions.module b/term_permissions.module
index acb1854..2e4584e 100644
--- a/term_permissions.module
+++ b/term_permissions.module
@@ -149,25 +149,21 @@ function term_permissions_form_alter(&$form, $form_state, $form_id) {
         }
         // If the user doesn't have access to any of the terms in the
         // vocabulary, remove the form item entirely.
-        if (count($options) <= 1) {
+        if (count($options) < 1) {
+          $vocabulary = $form[$field_name][$form[$field_name]['#language']];
           if ($vocabulary['#required']) {
             drupal_set_message(t("Your account doesn't have permission to
                   use any of the terms in the %vocabulary vocabulary. Your
                   account must be given permission to use at least one term in
-                  the %vocabulary vocabulary to be able to add or edit the
-                  %content-type content type.",
-                  array('%vocabulary' => $vocabulary['#title'],
-                    '%content-type' => node_get_types('name',
-                      $form['type']['#value']))), 'warning');
+                  the %vocabulary vocabulary to be able to add or edit items of this type.",
+                  array('%vocabulary' => $vocabulary['#title'])), 'warning');
+
             watchdog('term_permissions', '%user was blocked from accessing
                 the %content-type form as they do not have permission to use
-                any terms in the <a href="@vocabulary-url">%vocabulary</a>
+                any terms in the %vocabulary
                 vocabulary.', array('%user' => isset($user->name) ? $user->name : variable_get('anonymous', 'Anonymous'),
-                  '%content-type' => node_get_types('name', $form['type']['#value']),
-                  '@vocabulary-url' => url('admin/content/taxonomy/' . $vid),
                   '%vocabulary' => $vocabulary['#title']),
-                WATCHDOG_WARNING, l(t('edit vocabulary'),
-                  'admin/content/taxonomy/' . $vid));
+                WATCHDOG_WARNING);
             drupal_access_denied();
             exit();
           }
@@ -259,34 +255,24 @@ function term_permissions_allowed($tid, $user) {
   }
 
   // Are permissions enabled on this term?
-  if (!(db_query("SELECT COUNT(1) FROM {term_permissions_user} WHERE tid = :tid",
-          array(':tid' => $tid))->fetchField() ||
-        db_query("SELECT COUNT(1) FROM {term_permissions_role} WHERE tid = :tid",
-          array(':tid' => $tid))->fetchField())) {
-          return TRUE;
-  }
-  // We need to convert user->roles to be useful for us.
-  $users_uid = implode(', ', array_keys($user->roles));
-  // Permissions are enabled, check to see if this user or one of their roles
-  // is allowed
+  $query = db_select('term_permissions_user', 't')
+    ->fields('t', array('uid'))
+    ->condition('t.tid', $tid)
+    ->condition('t.uid', $user->uid);
 
-  $user_roles = array_keys($user->roles);
+  $users = $query->execute()->fetchField();
 
-  $i = 0;
+  $query = db_select('term_permissions_role', 't')
+    ->fields('t', array('rid'))
+    ->condition('t.tid', $tid)
+    ->condition('t.rid', array_keys($user->roles), 'IN');
 
-  while (isset($user_roles[$i])) {
+  $roles = $query->execute()->fetchField();
 
-  if (db_query("SELECT uid FROM {term_permissions_user} WHERE tid = :tid AND uid = :uid",
-  array(':tid' => $tid, ':uid' => $user->uid))->fetchField() ||
-      db_query("SELECT rid FROM {term_permissions_role} WHERE tid = :tid AND rid IN (:user_roles)",
-  array(':tid' => $tid, ':user_roles' => $user_roles[$i]))->fetchField()) {
+  if ($users || $roles) {
     return TRUE;
   }
 
-  $i++;
-
-  }
-
   return FALSE;
 }
 
