diff --git a/drupalvb.admin-pages.inc b/drupalvb.admin-pages.inc
index 6f8b964..d421c61 100644
--- a/drupalvb.admin-pages.inc
+++ b/drupalvb.admin-pages.inc
@@ -89,16 +89,18 @@ function drupalvb_settings_integration() {
  */
 function drupalvb_settings_database() {
   $form = array();
-  $db = parse_url(variable_get('drupalvb_db', is_array($GLOBALS['db_url']) ? $GLOBALS['db_url']['default'] : $GLOBALS['db_url']));
+  //echo DatabaseConnection::getKey();
+  $db = variable_get('drupalvb_db',array_shift(Database::getConnectionInfo()));
+
   $form['db'] = array(
     '#type' => 'fieldset',
     '#title' => t('Database connection'),
   );
-  $form['db']['scheme'] = array(
+  $form['db']['driver'] = array(
     '#type' => 'radios',
     '#title' => t('Database interface'),
     '#options' => array('mysql' => 'MySQL', 'mysqli' => 'MySQLi'),
-    '#default_value' => $GLOBALS['db_type'], // was: $db['scheme'],
+    '#default_value' => $db['driver'], 
     '#disabled' => TRUE,
     '#description' => t('Due to the database abstraction design in Drupal 5 and 6, only the current default database interface is supported.'),
   );
@@ -108,22 +110,22 @@ function drupalvb_settings_database() {
     '#default_value' => !empty($db['host']) ? $db['host'] : 'localhost',
     '#required' => TRUE,
   );
-  $form['db']['path'] = array(
+  $form['db']['database'] = array(
     '#type' => 'textfield',
     '#title' => t('Database'),
-    '#default_value' => substr($db['path'], 1),
+    '#default_value' => $db['database'],
     '#required' => TRUE,
   );
-  $form['db']['user'] = array(
+  $form['db']['username'] = array(
     '#type' => 'textfield',
     '#title' => t('Username'),
-    '#default_value' => $db['user'],
+    '#default_value' => $db['username'],
     '#required' => TRUE,
   );
-  $form['db']['pass'] = array(
+  $form['db']['password'] = array(
     '#type' => 'textfield',
     '#title' => t('Password'),
-    '#default_value' => $db['pass'],
+    '#default_value' => $db['password'],
     '#required' => TRUE,
   );
   $form['db']['db_prefix'] = array(
@@ -146,9 +148,7 @@ function drupalvb_settings_database_submit($form, &$form_state) {
     $initial_import = TRUE;
   }
 
-  $url = $form_state['values']['scheme'] .'://'. $form_state['values']['user'] .':'. $form_state['values']['pass'] .'@'. $form_state['values']['host'] .'/'. $form_state['values']['path'];
-  variable_set('drupalvb_db', $url);
-  variable_set('drupalvb_db_is_default', (is_array($GLOBALS['db_url']) ? $GLOBALS['db_url']['default'] == $url : $GLOBALS['db_url'] == $url));
+  variable_set('drupalvb_db', $form_state['values']);
   variable_set('drupalvb_db_prefix', $form_state['values']['db_prefix']);
 
   if ($initial_import) {
@@ -207,28 +207,17 @@ function drupalvb_settings_actions_submit($form, &$form_state) {
 function drupalvb_settings_variables() {
   $form = array();
   $options = drupalvb_get('options');
+ 
+  $header = array(t('Name'), t('Value'));
   foreach ($options as $key => $value) {
-    $form['variables'][$key]['name'] = array('#value' => check_plain($key));
-    $form['variables'][$key]['value'] = array('#value' => check_plain($value));
+    $rows[] = array(check_plain($key), check_plain($value));
   }
-  ksort($form['variables']);
-  return $form;
-}
 
-/**
- * Theme vBulletin options similar to Drupal variables (Devel).
- */
-function theme_drupalvb_settings_variables($form) {
-  $header = array(t('Name'), t('Value'));
-  $rows = array();
-  foreach (element_children($form['variables']) as $key) {
-    $rows[] = array(
-      drupal_render($form['variables'][$key]['name']),
-      drupal_render($form['variables'][$key]['value']),
-    );
-  }
-  $output = theme('table', $header, $rows);
-  $output .= drupal_render($form);
-  return $output;
-}
+  $form = array(
+    '#theme' => 'table',
+    '#header' => $header,
+    '#rows' => $rows,
+  );
 
+  return $form;
+}
diff --git a/drupalvb.inc b/drupalvb.inc
index d6abfb3..a923787 100644
--- a/drupalvb.inc
+++ b/drupalvb.inc
@@ -17,6 +17,20 @@
  */
 function drupalvb_db_connect() {
   global $db_url, $db_prefix;
+
+  $other_database = array(
+      'database' => 'forum',
+      'username' => 'root', // assuming this is necessary
+      'password' => 'root', // assuming this is necessary
+      'host' => 'localhost', // assumes localhost
+      'driver' => 'mysql', // replace with your database driver
+      'prefix' => variable_get('drupalvb_db_prefix', 'vb_'),
+    );
+  // replace 'YourDatabaseKey' with something that's unique to your module
+  Database::addConnectionInfo('vb', 'default', $other_database);
+  db_set_active('vb');
+  //todo: check if this is required
+  /*
   if (drupalvb_db_is_valid()) {
     if (!variable_get('drupalvb_db_is_default', TRUE)) {
       $drupalvb_db_url = variable_get('drupalvb_db', '');
@@ -31,6 +45,7 @@ function drupalvb_db_connect() {
     drupalvb_get_default_db_prefix();
     $db_prefix = variable_get('drupalvb_db_prefix', 'vb_');
   }
+   */
 }
 
 /**
@@ -39,6 +54,7 @@ function drupalvb_db_connect() {
  * @see drupalvb_db_connect(), drupalvb_get()
  */
 function drupalvb_db_disconnect() {
+  db_set_active();
   if (drupalvb_db_is_valid()) {
     if (!variable_get('drupalvb_db_is_default', TRUE)) {
       db_set_active();
@@ -77,6 +93,8 @@ function drupalvb_set_default_db_prefix() {
  * @see drupalvb_settings_system()
  */
 function drupalvb_db_is_valid() {
+  //todo: CHECK CONECTION!
+  return TRUE;
   global $db_url;
   static $valid;
 
@@ -153,19 +171,17 @@ function drupalvb_get($op) {
  *
  * @see db_query()
  */
-function drupalvb_db_query($query) {
+function drupalvb_db_query($query,$args = array(), $options = array()) {
   drupalvb_db_connect();
-
-  $args = func_get_args();
-  array_shift($args);
-  $query = db_prefix_tables($query);
-  if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
-    $args = $args[0];
-  }
-  _db_query_callback($args, TRUE);
-  $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
-  $result = _db_query($query);
-  
+  //todo: make prefix work
+  //$query = db_prefix_tables($query);
+  //if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
+   // $args = $args[0];
+  //}
+  //_db_query_callback($args, TRUE);
+  //$query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
+  //$result = db_query($query,$args);
+  $result = db_query($query, $args, $options);
   drupalvb_db_disconnect();
   return $result;
 }
@@ -175,22 +191,10 @@ function drupalvb_db_query($query) {
  *
   * @see db_query_range
  */
-function drupalvb_db_query_range($query) {
+function drupalvb_db_query_range($query, $args, $from, $count, $options = array()) {
   drupalvb_db_connect();
   
-  $args = func_get_args();
-  $count = array_pop($args);
-  $from = array_pop($args);
-  array_shift($args);
-
-  $query = db_prefix_tables($query);
-  if (isset($args[0]) and is_array($args[0])) { // 'All arguments in one array' syntax
-    $args = $args[0];
-  }
-  _db_query_callback($args, TRUE);
-  $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query);
-  $query .= ' LIMIT '. (int)$count .' OFFSET '. (int)$from;
-  $result = _db_query($query);
+  $result = db_query_range($query, $from, $count, $args, $options);
   
   drupalvb_db_disconnect();
   return $result;
@@ -202,7 +206,7 @@ function drupalvb_db_query_range($query) {
  * Borrowed from Drupal 6.
  */
 function drupalvb_db_last_insert_id($table, $field) {
-  return db_result(drupalvb_db_query('SELECT LAST_INSERT_ID()'));
+  return drupalvb_db_query('SELECT userid FROM {user} ORDER BY userid DESC LIMIT 1')->fetchField();
 }
 
 /**
@@ -217,16 +221,16 @@ function _drupalvb_init_user_map() {
   $users = $vbusers = array();
   // Fetch all users in Drupal.
   $result = db_query("SELECT uid, name FROM {users}");
-  while ($user = db_fetch_array($result)) {
-    $users[$user['name']] = $user['uid'];
+  foreach ($result as $user) {
+    $users[$user->name] = $user->uid;
   }
   // Fetch all users in vBulletin.
   $result = drupalvb_db_query("SELECT userid, username FROM {user}");
   // Insert all vB users who already exist in Drupal with corresponding username
   // into our mapping table.
-  while ($vbuser = db_fetch_array($result)) {
-    if (isset($users[$vbuser['username']])) {
-      db_query("INSERT INTO {drupalvb_users} (uid, userid) VALUES (%d, %d)", $users[$vbuser['username']], $vbuser['userid']);
+  foreach ($result as $vb_user) {
+    if (isset($users[$vbuser->username])) {
+      db_query("INSERT INTO {drupalvb_users} (uid, userid) VALUES (:uid, :userid)", array(":uid"=>$users[$vbuser->username], ":userid"=>$vbuser->userid));
     }
   }
 }
diff --git a/drupalvb.inc.php b/drupalvb.inc.php
index 84241b8..c2b93bd 100644
--- a/drupalvb.inc.php
+++ b/drupalvb.inc.php
@@ -19,7 +19,7 @@
  */
 function drupalvb_set_login_cookies($userid) {
   // Load required vB user data.
-  $vbuser = db_fetch_array(drupalvb_db_query("SELECT userid, password, salt FROM {user} WHERE userid = %d", $userid));
+  $vbuser = drupalvb_db_query("SELECT userid, password, salt FROM {user} WHERE userid = :userid", array(":userid" => $userid))->fetchAssoc();
   if (!$vbuser) {
     return FALSE;
   }
@@ -40,7 +40,7 @@ function drupalvb_set_login_cookies($userid) {
 
   // Clear out old session (if available).
   if (!empty($_COOKIE[$cookie_prefix .'sessionhash'])) {
-    drupalvb_db_query("DELETE FROM {session} WHERE sessionhash = '%s'", $_COOKIE[$cookie_prefix .'sessionhash']);
+    drupalvb_db_query("DELETE FROM {session} WHERE sessionhash = :hash", array(":hash" => $_COOKIE[$cookie_prefix .'sessionhash']));
   }
 
   // Setup user session.
@@ -48,7 +48,7 @@ function drupalvb_set_login_cookies($userid) {
   $idhash = md5($_SERVER['HTTP_USER_AGENT'] . $ip);
   $sessionhash = md5($now . request_uri() . $idhash . $_SERVER['REMOTE_ADDR'] . user_password(6));
 
-  drupalvb_db_query("REPLACE INTO {session} (sessionhash, userid, host, idhash, lastactivity, location, useragent, loggedin) VALUES ('%s', %d, '%s', '%s', %d, '%s', '%s', %d)", $sessionhash, $vbuser['userid'], substr($_SERVER['REMOTE_ADDR'], 0, 15), $idhash, $now, '/forum/', $_SERVER['HTTP_USER_AGENT'], 2);
+  drupalvb_db_query("REPLACE INTO {session} (sessionhash, userid, host, idhash, lastactivity, location, useragent, loggedin) VALUES (:hash, :userid, :host, :idhash, :lastactivity, :location, :useragent, :loggedin)", array(":hash" => $sessionhash, ":userid" => $vbuser['userid'], ":host" => substr($_SERVER['REMOTE_ADDR'], 0, 15), ":idhash" => $idhash, ":lastactivity" => $now, ":location" => '/forum/', ":useragent" => $_SERVER['HTTP_USER_AGENT'], ":loggedin" => 2));
 
   // Setup cookies.
   setcookie($cookie_prefix .'sessionhash', $sessionhash, $expire, $cookie_path, $vb_cookie_domain);
@@ -80,8 +80,8 @@ function drupalvb_clear_cookies($userid = NULL) {
   }
 
   if (!empty($userid)) {
-    drupalvb_db_query("DELETE FROM {session} WHERE userid = %d", $userid);
-    drupalvb_db_query("UPDATE {user} SET lastvisit = %d WHERE userid = %d", time(), $userid);
+    drupalvb_db_query("DELETE FROM {session} WHERE userid = :userid", array(":userid"=>$userid));
+    drupalvb_db_query("UPDATE {user} SET lastvisit = :time WHERE userid = :userid", array(":time" => time(), ":userid" => $userid));
   }
 
   setcookie($cookie_prefix .'sessionhash', '', $expire, $cookie_path, $vb_cookie_domain);
@@ -125,7 +125,7 @@ function drupalvb_get_ip() {
  */
 function drupalvb_create_user($account, $edit) {
   // Ensure we are not duplicating a user.
-  if (db_result(drupalvb_db_query("SELECT COUNT(userid) FROM {user} WHERE LOWER(username) = LOWER('%s')", drupalvb_htmlspecialchars($edit['name']))) > 0) {
+  if (drupalvb_db_query("SELECT COUNT(userid) FROM {user} WHERE LOWER(username) = LOWER(:name)",array(':name' => drupalvb_htmlspecialchars($edit['name'])))->fetchField() > 0) {
     return FALSE;
   }
 
@@ -141,12 +141,13 @@ function drupalvb_create_user($account, $edit) {
     $passhash = md5(md5($edit['pass']) . $salt);
   }
 
-  $passdate = date('Y-m-d', $account->created);
-  $joindate = $account->created;
+  $time = $account->created;
+  $passdate = date('Y-m-d', $time);
+  $joindate = $time;
 
   // Attempt to grab the user title from the database.
   $result = drupalvb_db_query("SELECT title FROM {usertitle} WHERE minposts = 0");
-  if ($resarray = db_fetch_array($result)) {
+  if ($resarray = $result->fetchAssoc()) {
     $usertitle = $resarray['title'];
   }
   else {
@@ -163,14 +164,17 @@ function drupalvb_create_user($account, $edit) {
 
   // Default usergroup id.
   $usergroupid = variable_get('drupalvb_default_usergroup', '2');
-
+  $lid = drupalvb_get('languageid');
+  if(is_null($lid)) {
+    $lid = 1;
+  }
   // Set up the insertion query.
-  $result = drupalvb_db_query("INSERT INTO {user} (username, usergroupid, password, passworddate, usertitle, email, salt, showvbcode, languageid, timezoneoffset, posts, joindate, lastvisit, lastactivity, options) VALUES ('%s', '%s', '%s', '%s', '%s', '%s', '%s', 1, %d, '%s', 0, '%s', '%s', '%s', '%s')", drupalvb_htmlspecialchars($edit['name']), $usergroupid, $passhash, $passdate, $usertitle, $edit['mail'], $salt, drupalvb_get('languageid'), $timezone, $joindate, time(), time(), $options);
+  $result = drupalvb_db_query("INSERT INTO {user} (username, usergroupid, password, passworddate, usertitle, email, salt, showvbcode, languageid, timezoneoffset, posts, joindate, lastvisit, lastactivity, options) VALUES (:username, :groupid, :password, :passworddate, :usertitle, :email, :salt, 1, :languageid, :timezoneoffset, 0, :joindate, :lastvisit, :lastactivity, :options)", array(":username" => drupalvb_htmlspecialchars($edit['name']), ":groupid" => $usergroupid, ":password" => $passhash, ":passworddate" => $passdate, ":usertitle" => $usertitle, ":email" => $edit['mail'], ":salt" => $salt, ":languageid" => 1, ":timezoneoffset" => $timezone, ":joindate" => $joindate, ":lastvisit" => time(), ":lastactivity" => time(), ":options" => $options));
 
   $userid = drupalvb_db_last_insert_id('user', 'userid');
 
-  drupalvb_db_query("INSERT INTO {userfield} (userid) VALUES (%d)", $userid);
-  drupalvb_db_query("INSERT INTO {usertextfield} (userid) VALUES (%d)", $userid);
+  drupalvb_db_query("INSERT INTO {userfield} (userid) VALUES (:userid)", array(":userid" => $userid));
+  drupalvb_db_query("INSERT INTO {usertextfield} (userid) VALUES (:userid)", array(":userid" => $userid));
 
   // Insert new user into mapping table.
   drupalvb_set_mapping($account->uid, $userid);
@@ -191,46 +195,46 @@ function drupalvb_update_user($account, $edit) {
     }
     switch ($field) {
       case 'name':
-        $fields[] = "username = '%s'";
-        $values[] = drupalvb_htmlspecialchars($value);
+        $fields[] = "username = :name";
+        $values[':name'] = drupalvb_htmlspecialchars($value);
         break;
 
       case 'pass':
-        $fields[] = "password = '%s'";
+        $fields[] = "password = :password";
         // Note: Password is already hashed during user export.
         if (isset($edit['md5pass'])) {
-          $values[] = md5($edit['md5pass'] . $edit['salt']);
+          $values[':password'] = md5($edit['md5pass'] . $edit['salt']);
         }
         else {
-          $values[] = md5(md5($value) . $edit['salt']);
+          $values[':password'] = md5(md5($value) . $edit['salt']);
         }
-        $fields[] = "salt = '%s'";
-        $values[] = $edit['salt'];
-        $fields[] = "passworddate = '%s'";
-        $values[] = date('Y-m-d', time());
+        $fields[] = "salt = :salt";
+        $values[':salt'] = $edit['salt'];
+        $fields[] = "passworddate = :date";
+        $values[':date'] = date('Y-m-d', time());
         break;
 
       case 'mail':
-        $fields[] = "email = '%s'";
-        $values[] = $value;
+        $fields[] = "email = :email";
+        $values[':email'] = $value;
         break;
 
       case 'language':
-        $fields[] = "languageid = %d";
-        $values[] = drupalvb_get('languageid', $value);
+        $fields[] = "languageid = :lid";
+        $values[':lid'] = 1;//drupalvb_get('languageid', $value);
         break;
     }
   }
-  $fields[] = 'lastactivity = %d';
-  $values[] = time();
+  $fields[] = 'lastactivity = :activity';
+  $values[':activity'] = time();
 
   // Use previous case insensitive username to update conflicting names.
-  $values[] = drupalvb_htmlspecialchars($account->name);
-  drupalvb_db_query("UPDATE {user} SET ". implode(', ', $fields) ." WHERE LOWER(username) = LOWER('%s')", $values);
+  $values[':username'] = drupalvb_htmlspecialchars($account->name);
+  drupalvb_db_query("UPDATE {user} SET ". implode(', ', $fields) ." WHERE LOWER(username) = LOWER(:username)", $values);
 
   // Ensure this user exists in the mapping table.
   // When integrating an existing installation, the mapping may not yet exist.
-  $userid = db_result(drupalvb_db_query("SELECT userid FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($account->name)));
+  $userid = drupalvb_db_query("SELECT userid FROM {user} WHERE username = :name", array(":name"=>drupalvb_htmlspecialchars($account->name)))->fetchField();
   drupalvb_set_mapping($account->uid, $userid);
 }
 
@@ -243,7 +247,7 @@ function drupalvb_update_user($account, $edit) {
  *   A vBulletin user id.
  */
 function drupalvb_set_mapping($uid, $userid) {
-  db_query("INSERT IGNORE INTO {drupalvb_users} (uid, userid) VALUES (%d, %d)", $uid, $userid);
+  db_query("INSERT IGNORE INTO {drupalvb_users} (uid, userid) VALUES (:uid, :userid)", array(':uid'=>$uid, ':userid'=>$userid));
 }
 
 /**
@@ -253,7 +257,7 @@ function drupalvb_export_drupal_users() {
   module_load_include('inc', 'drupalvb');
 
   $result = db_query("SELECT * FROM {users} ORDER BY uid");
-  while ($user = db_fetch_object($result)) {
+  foreach ($result as $user) {
     if ($user->uid == 0) {
       continue;
     }
@@ -262,7 +266,7 @@ function drupalvb_export_drupal_users() {
     if (!drupalvb_create_user($user, (array)$user)) {
       // Username already exists, update email and password only.
       // Case insensitive username is required to detect collisions.
-      $vbuser = db_fetch_array(drupalvb_db_query("SELECT salt FROM {user} WHERE LOWER(username) = LOWER('%s')", drupalvb_htmlspecialchars($user->name)));
+      $vbuser = drupalvb_db_query("SELECT salt FROM {user} WHERE LOWER(username) = LOWER(:name)", array(":name"=>drupalvb_htmlspecialchars($user->name)))->fetchAssoc();
       drupalvb_update_user($user, array_merge((array)$user, $vbuser));
     }
   }
@@ -276,8 +280,8 @@ function drupalvb_get_options() {
 
   if (empty($options)) {
     $result = db_query("SELECT varname, value FROM {setting}");
-    while ($var = db_fetch_array($result)) {
-      $options[$var['varname']] = $var['value'];
+    foreach ($result as $var) {
+      $options[$var->varname] = $var->value;
     }
   }
   return $options;
@@ -329,7 +333,7 @@ function drupalvb_get_roles() {
   $result = drupalvb_db_query("SELECT usergroupid, title FROM {usergroup}");
 
   $roles = array();
-  while ($data = db_fetch_object($result)) {
+  foreach ($result as $data) {
     $roles[$data->usergroupid] = $data->title;
   }
   if (!$roles) {
@@ -342,17 +346,18 @@ function drupalvb_get_roles() {
  * Get vB language id by given ISO language code.
  */
 function drupalvb_get_languageid($language = NULL) {
-  static $vblanguages;
+  //static $vblanguages 
 
   if (!isset($vblanguages)) {
     $vblanguages = array();
     $result = drupalvb_db_query("SELECT languageid, title, languagecode FROM {language}");
-    while ($lang = db_fetch_array($result)) {
-      $vblanguages[$lang['languagecode']] = $lang['languageid'];
+    foreach ($result as $lang) {
+      $vblanguages[$lang->languagecode] = $lang->languageid;
     }
   }
   $options = drupalvb_get('options');
-  return (!empty($language) && isset($vblanguages[$language]) ? $vblanguages[$language] : $vblanguages[$options['languageid']]);
+  return 1;
+  //return (!empty($language) && isset($vblanguages[$language]) ? $vblanguages[$language] : $vblanguages[$options['languageid']]);
 }
 
 /**
@@ -366,11 +371,11 @@ function drupalvb_get_users_online() {
   $numberregistered = 0;
   $numberguest      = 0;
 
-  $result = drupalvb_db_query("SELECT user.username, user.usergroupid, session.userid, session.lastactivity FROM {session} AS session LEFT JOIN {user} AS user ON (user.userid = session.userid) WHERE session.lastactivity > %d", $datecut);
+  $result = drupalvb_db_query("SELECT user.username, user.usergroupid, session.userid, session.lastactivity FROM {session} AS session LEFT JOIN {user} AS user ON (user.userid = session.userid) WHERE session.lastactivity > :datecut", array(":datecut"=>$datecut));
 
   $userinfos = array();
 
-  while ($loggedin = db_fetch_array($result)) {
+  while ($loggedin = $result->fetchAssoc()) {
     $userid = $loggedin['userid'];
     if (!$userid) {
       $numberguest++;
@@ -392,18 +397,18 @@ function drupalvb_get_recent_posts($scope = 'last') {
   global $user;
 
   // Queries the vB user database to find a matching set of user data.
-  $result = drupalvb_db_query("SELECT userid, username, lastvisit FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($user->name));
+  $result = drupalvb_db_query("SELECT userid, username, lastvisit FROM {user} WHERE username = :name", array(':name'=>drupalvb_htmlspecialchars($user->name)));
 
   // Make sure a user is logged in to get their last visit and appropriate post
   // count.
-  if ($vb_user = db_fetch_array($result)) {
+  if ($vb_user = $result->fetchAssoc()) {
     if ($scope == 'last') {
       $datecut = $vb_user['lastvisit'];
     }
     else if ($scope == 'daily') {
       $datecut = time() - 86400;
     }
-    $posts = db_result(drupalvb_db_query("SELECT COUNT(postid) FROM {post} WHERE dateline > %d", $datecut));
+    $posts = drupalvb_db_query("SELECT COUNT(postid) FROM {post} WHERE dateline > :datecut", array(":datecut"=>$datecut))->fetchField();
   }
   else {
     $posts = 0;
diff --git a/drupalvb.info b/drupalvb.info
index d35c7bd..d1c89ce 100644
--- a/drupalvb.info
+++ b/drupalvb.info
@@ -1,3 +1,3 @@
 name = Drupal vB
 description = Integrate your Drupal site with vBulletin forums.
-core = 6.x
+core = 7.x
diff --git a/drupalvb.install b/drupalvb.install
index 9fff731..4a0237b 100644
--- a/drupalvb.install
+++ b/drupalvb.install
@@ -44,17 +44,9 @@ function drupalvb_schema() {
 }
 
 /**
- * Implementation of hook_install().
- */
-function drupalvb_install() {
-  drupal_install_schema('drupalvb');
-}
-
-/**
  * Implementation of hook_uninstall().
  */
 function drupalvb_uninstall() {
-  drupal_uninstall_schema('drupalvb');
   db_query("DELETE FROM {variable} WHERE name LIKE 'drupalvb_%%'");
 }
 
diff --git a/drupalvb.module b/drupalvb.module
index 07293c1..100e39d 100644
--- a/drupalvb.module
+++ b/drupalvb.module
@@ -8,6 +8,7 @@
  */
 
 require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc.php';
+require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc';
 
 /**
  * Implementation of hook_theme().
@@ -15,19 +16,19 @@ require_once drupal_get_path('module', 'drupalvb') .'/drupalvb.inc.php';
 function drupalvb_theme() {
   return array(
     'drupalvb_block_recent' => array(
-      'arguments' => array('recent' => NULL, 'vb_options' => NULL),
+      'variables' => array('recent' => NULL, 'vb_options' => NULL),
     ),
     'drupalvb_block_recent_user' => array(
-      'arguments' => array('recent' => NULL, 'vb_options' => NULL),
+      'variables' => array('recent' => NULL, 'vb_options' => NULL),
     ),
     'drupalvb_block_top_posters' => array(
-      'arguments' => array('items' => array()),
+      'variables' => array('items' => array()),
     ),
     'drupalvb_username' => array(
-      'arguments' => array('object' => NULL, 'class' => NULL),
+      'variables' => array('object' => NULL, 'class' => NULL),
     ),
     'drupalvb_settings_variables' => array(
-      'arguments' => array('form' => array()),
+      'variables' => array('form' => array()),
     ),
   );
 }
@@ -52,10 +53,15 @@ function drupalvb_help($path, $arg) {
         l(t('Forum Admin Control Panel'), $vb_options['bburl'] .'/'. $vb_config['Misc']['admincpdir']),
         l(t('Forum Moderator Control Panel'), $vb_options['bburl'] .'/'. $vb_config['Misc']['modcpdir']),
       );
-      return theme_item_list($items);
+      return theme_item_list(array(
+        "items" => $items,
+        "title" => "", 
+        "type" => "ul",
+        "attributes" => array(),
+      ));
 
     case 'admin/help#drupalvb':
-      return filter_filter('process', 2, NULL, file_get_contents(dirname(__FILE__) .'/README.txt'));
+      return file_get_contents(dirname(__FILE__) .'/README.txt');
   }
 }
 
@@ -165,9 +171,9 @@ function drupalvb_form_alter(&$form, $form_state, $form_id) {
 
     // Splice in our validate handler for authentication if user is performing
     // a vBulletin login.
-    if (!empty($form_state['post']['name']) && drupalvb_db_is_valid()) {
-      $username = $form_state['post']['name'];
-      if ($vbuser = db_fetch_array(drupalvb_db_query("SELECT userid, password, salt, email FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($username)))) {
+    if (!empty($form_state['input']['name']) && drupalvb_db_is_valid()) {
+      $username = $form_state['input']['name'];
+      if ($vbuser = drupalvb_db_query("SELECT userid, password, salt, email FROM {user} WHERE username = :username", array(":username"=>drupalvb_htmlspecialchars($username)))->fetchAssoc()) {       
         $key = array_search('user_login_final_validate', $form['#validate']);
         if ($key !== FALSE) {
           array_splice($form['#validate'], $key, 0, 'drupalvb_login_validate');
@@ -183,6 +189,7 @@ function drupalvb_form_alter(&$form, $form_state, $form_id) {
   else if ($form_id == 'user_pass') {
     $form['#validate'] = array_merge(array('drupalvb_user_pass_validate'), $form['#validate']);
   }
+
 }
 
 /**
@@ -190,7 +197,6 @@ function drupalvb_form_alter(&$form, $form_state, $form_id) {
  */
 function drupalvb_login_validate($form, &$form_state) {
   global $user;
-
   if (!variable_get('drupalvb_dual_login', TRUE)) {
     return;
   }
@@ -204,9 +210,9 @@ function drupalvb_login_validate($form, &$form_state) {
   if (empty($username) || empty($password)) {
     return;
   }
-
+  $uid = db_query("SELECT uid FROM users WHERE name='$username'")->fetchField();
   // If this user already exists in Drupal, no further validation required.
-  $finduser = user_load(array('name' => $username));
+  $finduser = user_load($uid);
   if ($finduser && $finduser->uid) {
     return TRUE;
   }
@@ -215,7 +221,7 @@ function drupalvb_login_validate($form, &$form_state) {
   if (!drupalvb_db_is_valid()) {
     return;
   }
-  if ($vbuser = db_fetch_array(drupalvb_db_query("SELECT userid, username, password, salt, email, joindate FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($username)))) {
+  if ($vbuser = drupalvb_db_query("SELECT userid, username, password, salt, email, joindate FROM {user} WHERE username = :username", array(":username" => drupalvb_htmlspecialchars($username)))->fetchAssoc()) {
     // Rebuild the password.
     $vbpassword = md5(md5($password) . $vbuser['salt']);
     if ($vbuser['password'] === $vbpassword) {
@@ -224,9 +230,9 @@ function drupalvb_login_validate($form, &$form_state) {
       // find a user with the given password, otherwise we wouldn't be here.
       // This can happen if the user has been temporarily created by
       // drupalvb_redirect().
-      if ($uid = drupalvb_user_load($vbuser['userid'])) {
+      if ($uid = drupalvb_vb_user_load($vbuser['userid'])) {
         // Only update the password of the existing Drupal user record.
-        $account = user_load(array('uid' => $uid));
+        $account = user_load($uid);
         $userinfo['pass'] = $password;
         $user = user_save($account, $userinfo);
       }
@@ -244,7 +250,7 @@ function drupalvb_login_validate($form, &$form_state) {
           'status' => 1,
         );
         $user = user_save('', $userinfo);
-        watchdog('drupalvb', t('New external user: %user.', array('%user' => $user->name)), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
+        watchdog('drupalvb', t('New external user: %user.', array('%user' => $user->name)),array(), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
 
         // Update the mapping table.
         drupalvb_set_mapping($user->uid, $vbuser['userid']);
@@ -265,7 +271,6 @@ function drupalvb_login_validate($form, &$form_state) {
  */
 function drupalvb_user_pass_validate($form, $form_state) {
   $name = $form_state['values']['name'];
-
   // Return if the given user exists in Drupal.
   if (user_load(array('name' => $name)) || user_load(array('mail' => $name))) {
     return;
@@ -274,7 +279,7 @@ function drupalvb_user_pass_validate($form, $form_state) {
   module_load_include('inc', 'drupalvb');
 
   // Try to import a corresponding user from vB.
-  if ($userid = db_result(drupalvb_db_query("SELECT userid FROM {user} WHERE username = '%s' OR email = '%s'", drupalvb_htmlspecialchars($name), $name))) {
+  if ($userid = drupalvb_db_query("SELECT userid FROM {user} WHERE username = :username OR email = :email", array(":username" => drupalvb_htmlspecialchars($name), ":email"=> $name))->fetchField()) {
     drupalvb_lookup_drupal_user($userid);
   }
 }
@@ -286,52 +291,8 @@ function drupalvb_user_pass_validate($form, $form_state) {
  * @param $userid
  *   A vBulletin user id.
  */
-function drupalvb_user_load($userid) {
-  return db_result(db_query("SELECT uid FROM {drupalvb_users} WHERE userid = %d", $userid));
-}
-
-/**
- * Implementation of hook_user().
- */
-function drupalvb_user($op, &$edit, &$account, $category = NULL) {
-  module_load_include('inc', 'drupalvb');
-  if (!drupalvb_db_is_valid()) {
-    return;
-  }
-
-  switch ($op) {
-    case 'login':
-    case 'logout':
-      if (variable_get('drupalvb_dual_login', TRUE)) {
-        $function = 'drupalvb_user_'. $op;
-        return $function($account);
-      }
-      break;
-
-    case 'validate':
-      if ($category == 'account' && (variable_get('drupalvb_acct_generation', TRUE) || variable_get('drupalvb_acct_sync', TRUE))) {
-        return drupalvb_user_validate(arg(1), $edit);
-      }
-      break;
-
-    case 'insert':
-      if (variable_get('drupalvb_acct_generation', TRUE)) {
-        return drupalvb_user_insert($account, $edit);
-      }
-      break;
-
-    case 'update':
-      if (variable_get('drupalvb_acct_sync', TRUE)) {
-        return drupalvb_user_update($account, $edit);
-      }
-      break;
-
-    case 'delete':
-      if (variable_get('drupalvb_acct_sync', TRUE)) {
-        return drupalvb_user_delete($account);
-      }
-      break;
-  }
+function drupalvb_vb_user_load($userid) {
+  return db_query("SELECT uid FROM {drupalvb_users} WHERE userid = :userid", array(":userid"=>$userid))->fetchField();
 }
 
 /**
@@ -339,8 +300,8 @@ function drupalvb_user($op, &$edit, &$account, $category = NULL) {
  *
  * @see drupalvb_user()
  */
-function drupalvb_user_login($account) {
-  $vbuser = db_fetch_array(drupalvb_db_query_range("SELECT u.userid, ub.liftdate FROM {user} u LEFT JOIN {userban} ub ON ub.userid = u.userid WHERE u.username = '%s'", drupalvb_htmlspecialchars($account->name), 0, 1));
+function drupalvb_user_login(&$edit, $account) {
+$vbuser = drupalvb_db_query("SELECT u.userid, ub.liftdate FROM {user} u LEFT JOIN {userban} ub ON ub.userid = u.userid WHERE u.username = :username", array(":username" => drupalvb_htmlspecialchars($account->name)))->fetchAssoc();
 
   // Create account in vB if user does not exist.
   if (!$vbuser) {
@@ -357,8 +318,7 @@ function drupalvb_user_login($account) {
   else {
     return FALSE;
   }
-
-  // Setup vB user session and cookies.
+// Setup vB user session and cookies.
   if (drupalvb_set_login_cookies($vbuser['userid'])) {
     return TRUE;
   }
@@ -375,7 +335,7 @@ function drupalvb_user_login($account) {
  * @see drupalvb_user()
  */
 function drupalvb_user_logout($account) {
-  $vbuser = db_fetch_array(drupalvb_db_query_range("SELECT userid, username FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($account->name), 0, 1));
+  $vbuser = drupalvb_db_query("SELECT userid, username FROM {user} WHERE username = :name", array(":name"=>drupalvb_htmlspecialchars($account->name)))->fetchAssoc();
   if ($vbuser) {
     // Remove all vB cookies for current user.
     drupalvb_clear_cookies($vbuser['userid']);
@@ -386,18 +346,21 @@ function drupalvb_user_logout($account) {
 /**
  * Ensure a username or e-mail address does not already exist in vB.
  */
-function drupalvb_user_validate($uid, &$edit) {
-  $userid = db_result(db_query("SELECT userid FROM {drupalvb_users} WHERE uid = %d", $uid));
+function drupalvb_user_presave(&$edit, $account) {
+  $uid = $account->uid;
+  $userid = db_query("SELECT userid FROM {drupalvb_users} WHERE uid = :uid", array(":uid" => $uid))->fetchField();
   // Validate the username.
   if (arg(1) == 'register' || user_access('change own username') || user_access('administer users')) {
-    if (db_result(drupalvb_db_query_range("SELECT userid FROM {user} WHERE userid <> %d AND LOWER(username) = LOWER('%s')", $userid, drupalvb_htmlspecialchars($edit['name']), 0, 1))) {
+    if (drupalvb_db_query("SELECT COUNT(userid) FROM {user} WHERE userid <> :userid AND LOWER(username) = LOWER(:name)", array(":userid" => $userid, ":name" => drupalvb_htmlspecialchars($edit['name'])))->fetchField() > 0) {
       form_set_error('name', t('The name %name is already taken.', array('%name' => $edit['name'])));
+      drupal_goto($_GET['q']);
     }
   }
 
   // Validate the e-mail address.
-  if (db_result(drupalvb_db_query_range("SELECT userid FROM {user} WHERE userid <> %d AND LOWER(email) = LOWER('%s')", $userid, drupalvb_htmlspecialchars($edit['mail']), 0, 1)) > 0) {
+  if (drupalvb_db_query("SELECT COUNT(userid) FROM {user} WHERE userid <> :userid AND LOWER(email) = LOWER(:email)", array(":userid" => $userid, ":email" => drupalvb_htmlspecialchars($edit['mail'])))->fetchField() > 0) {
     form_set_error('mail', t('The e-mail address %email is already registered. <a href="@password">Have you forgotten your password?</a>', array('%email' => $edit['mail'], '@password' => url('user/password'))));
+      drupal_goto($_GET['q']);
   }
 }
 
@@ -406,12 +369,16 @@ function drupalvb_user_validate($uid, &$edit) {
  *
  * @see drupalvb_user()
  */
-function drupalvb_user_insert($account, $edit) {
+function drupalvb_user_insert($edit, $account) {
   global $user;
-
-  if ($userid = drupalvb_create_user($account, $edit)) {
+  
+  /*if(!drupalvb_user_validate($account->uid, $edit)) {
+    user_delete($account->uid);
+  }*/
+ 
+  if ($userid = drupalvb_create_user($account, (array)$edit)) {
     // Prevent overriding cookies of administrators.
-    if ($edit['name'] === $user->name) {
+    if ($edit['name'] === $account->name) {
       drupalvb_set_login_cookies($userid);
     }
   }
@@ -422,11 +389,11 @@ function drupalvb_user_insert($account, $edit) {
  *
  * @see drupalvb_user()
  */
-function drupalvb_user_update($account, $edit) {
+function drupalvb_user_update($edit, $account) {
   global $user;
-
+ 
   // Update data if user exists.
-  if ($vbuser = db_fetch_array(drupalvb_db_query_range("SELECT userid, salt FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($account->name), 0, 1))) {
+  if ($vbuser = drupalvb_db_query_range("SELECT userid, salt FROM {user} WHERE username = :name", array(":name" => drupalvb_htmlspecialchars($account->name)), 0, 1)->fetchAssoc()) {
     // Merge current username, salt, and finally edited values into one array,
     // so usernames may be altered (if allowed).
     drupalvb_update_user($account, array_merge(array('name' => $account->name), $vbuser, $edit));
@@ -459,7 +426,7 @@ function drupalvb_user_delete($account) {
     drupalvb_db_query("DELETE FROM {usertextfield} WHERE userid = %d", $userid);
   }
   // Delete from mapping table.
-  db_query("DELETE FROM {drupalvb_users} WHERE uid = %d", $account->uid);
+  db_query("DELETE FROM {drupalvb_users} WHERE uid = :uid", array(":uid" => $account->uid));
 }
 
 /**
@@ -554,89 +521,110 @@ function drupalvb_panels_include_directory($plugintype) {
 }
 
 /**
- * Implementation of hook_block().
+ * Implements hook_block_info()
  */
-function drupalvb_block($op = 'list', $delta = 0, $edit = array()) {
-  global $user;
-
-  if ($op == 'list') {
-    $blocks = array();
-    $blocks['recent']['info'] = t('vBulletin: Recent forum threads/posts');
-    $blocks['recent_user']['info'] = t('vBulletin: Recent posts by user (user account)');
-    $blocks['top_posters']['info'] = t('vBulletin: User list of top forum posters');
-    $blocks['user']['info'] = t('vBulletin: User info');
-    $blocks['stats']['info'] = t('vBulletin: Overall statistics');
-    return $blocks;
-  }
-  else if ($op == 'configure') {
-    $form = array();
-    switch ($delta) {
-      case 'recent':
-        $form['drupalvb_block_recent_type'] = array(
-          '#type' => 'radios',
-          '#title' => t('Type of displayed items'),
-          '#default_value' => variable_get('drupalvb_block_recent_type', 'threads'),
-          '#options' => array(
-            'threads' => t('Recent forum threads'),
-            'posts' => t('Recent forum posts'),
-          ),
-          '#description' => t('Please choose whether the block should display recent threads or posts.'),
-        );
-        $form['drupalvb_block_recent_count'] = array(
-          '#type' => 'select',
-          '#title' => t('Number of items'),
-          '#default_value' => variable_get('drupalvb_block_recent_count', 5),
-          '#options' => drupal_map_assoc(range(1, 12)),
-        );
-        $form['drupalvb_block_recent_limit'] = array(
-          '#type' => 'select',
-          '#title' => t('Timeframe threshold'),
-          '#default_value' => variable_get('drupalvb_block_recent_limit', 7),
-          '#options' => drupal_map_assoc(array_merge(range(1, 8), range(14, 30, 7), range(30, 360, 30))),
-          '#description' => t('How many days back you want the recent posts/threads to include.'),
-        );
-        $form['drupalvb_block_recent_authors'] = array(
-          '#type' => 'checkbox',
-          '#title' => t('Display author names'),
-          '#default_value' => variable_get('drupalvb_block_recent_authors', 0),
-          '#return_value' => 1,
-          '#description' => t('Enable this option to display author names for recent threads/posts.'),
-        );
-        return $form;
+function drupalvb_block_info() {
+  $blocks = array();
+  $blocks['recent'] = array(
+    'info' => t('vBulletin: Recent forum threads/posts'),
+    'cache' => DRUPAL_NO_CACHE
+  );
+  $blocks['recent_user'] = array(
+    'info' => t('vBulletin: Recent posts by user (user account)'),
+    'cache' => DRUPAL_NO_CACHE
+  );
+  $blocks['top_posters'] = array(
+    'info' => t('vBulletin: User list of top forum posters'),
+    'cache' => DRUPAL_NO_CACHE,
+  );
+  $blocks['user'] = array(
+    'info' => t('vBulletin: User info'),
+    'cache' => DRUPAL_NO_CACHE,
+  );
+  $blocks['stats'] = array(
+    'info' => t('vBulletin: Overall statistics'),
+    'cache' => DRUPAL_NO_CACHE,
+  );
 
-      case 'user':
-        $form['drupalvb_block_user'] = array(
-          '#type' => 'checkboxes',
-          '#title' => t('Display Options'),
-          '#default_value' => variable_get('drupalvb_block_user', drupal_map_assoc(array('newposts', 'recent', 'online', 'pms'))),
-          '#options' => array(
-            'newposts' => t('New posts (since last visit)'),
-            'recent' => t('Recent posts (last 24 hours)'),
-            'online' => t('Users online'),
-            'pms' => t('New private messages'),
-          ),
-          '#description' => t('Please select which information should be displayed in the user info block.'),
-        );
-        return $form;
+  return $blocks;
+}
 
-      case 'stats':
-        $form['drupalvb_block_stats'] = array(
-          '#type' => 'checkboxes',
-          '#title' => t('Display Options'),
-          '#default_value' => variable_get('drupalvb_block_stats', drupal_map_assoc(array('threads', 'posts', 'tmembers', 'amembers'))),
-          '#options' => array(
-            'threads' => t('Total Threads'),
-            'posts' => t('Total Posts'),
-            'tmembers' => t('Total Members'),
-            'amembers' => t('Active Members'),
+/**
+ * Implements hook_block_configure()
+ */
+function drupalvb_block_configure($delta = '') {
+  $form = array();
+  switch ($delta) {
+  case 'recent':
+    $form['drupalvb_block_recent_type'] = array(
+      '#type' => 'radios',
+      '#title' => t('Type of displayed items'),
+      '#default_value' => variable_get('drupalvb_block_recent_type', 'threads'),
+      '#options' => array(
+        'threads' => t('Recent forum threads'),
+        'posts' => t('Recent forum posts'),
+      ),
+      '#description' => t('Please choose whether the block should display recent threads or posts.'),
+    );
+    $form['drupalvb_block_recent_count'] = array(
+      '#type' => 'select',
+      '#title' => t('Number of items'),
+      '#default_value' => variable_get('drupalvb_block_recent_count', 5),
+      '#options' => drupal_map_assoc(range(1, 12)),
+    );
+    $form['drupalvb_block_recent_limit'] = array(
+      '#type' => 'select',
+      '#title' => t('Timeframe threshold'),
+      '#default_value' => variable_get('drupalvb_block_recent_limit', 7),
+      '#options' => drupal_map_assoc(array_merge(range(1, 8), range(14, 30, 7), range(30, 360, 30))),
+      '#description' => t('How many days back you want the recent posts/threads to include.'),
+    );
+    $form['drupalvb_block_recent_authors'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Display author names'),
+      '#default_value' => variable_get('drupalvb_block_recent_authors', 0),
+      '#return_value' => 1,
+      '#description' => t('Enable this option to display author names for recent threads/posts.'),
+    );
+    return $form;
+
+  case 'user':
+    $form['drupalvb_block_user'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Display Options'),
+      '#default_value' => variable_get('drupalvb_block_user', drupal_map_assoc(array('newposts', 'recent', 'online', 'pms'))),
+      '#options' => array(
+        'newposts' => t('New posts (since last visit)'),
+        'recent' => t('Recent posts (last 24 hours)'),
+        'online' => t('Users online'),
+        'pms' => t('New private messages'),
+      ),
+      '#description' => t('Please select which information should be displayed in the user info block.'),
+    );
+    return $form;
+
+  case 'stats':
+    $form['drupalvb_block_stats'] = array(
+      '#type' => 'checkboxes',
+      '#title' => t('Display Options'),
+      '#default_value' => variable_get('drupalvb_block_stats', drupal_map_assoc(array('threads', 'posts', 'tmembers', 'amembers'))),
+      '#options' => array(
+        'threads' => t('Total Threads'),
+        'posts' => t('Total Posts'),
+        'tmembers' => t('Total Members'),
+        'amembers' => t('Active Members'),
           ),
           '#description' => t('Choose what information is shown in the Forum Admin block.'),
         );
         return $form;
     }
-  }
-  else if ($op == 'save') {
-    if ($delta == 'recent') {
+    
+}
+/**
+ * Implementation of hook_block_save().
+ */
+function hook_block_save($delta = '', $edit = array()) {
+  if ($delta == 'recent') {
       variable_set('drupalvb_block_recent_type', $edit['drupalvb_block_recent_type']);
       variable_set('drupalvb_block_recent_count', $edit['drupalvb_block_recent_count']);
       variable_set('drupalvb_block_recent_limit', $edit['drupalvb_block_recent_limit']);
@@ -645,47 +633,54 @@ function drupalvb_block($op = 'list', $delta = 0, $edit = array()) {
     else {
       variable_set('drupalvb_block_'. $delta, $edit['drupalvb_block_'. $delta]);
     }
+
+}
+
+/**
+ * Implements hook_block_view()
+ */
+function drupalvb_block_view($delta = '') {
+  $block = array();
+
+  module_load_include('inc', 'drupalvb');
+  $block = array();
+  if (!drupalvb_db_is_valid()) {
+    return $block;
   }
-  else if ($op == 'view') {
-    module_load_include('inc', 'drupalvb');
-    $block = array();
-    if (!drupalvb_db_is_valid()) {
+  switch ($delta) {
+  case 'recent':
+    $display = variable_get('drupalvb_block_recent_type', 'threads');
+    $block['subject'] = ($display == 'threads' ? t('Recent forum threads') : t('Recent forum posts'));
+    $block['content'] = drupalvb_block_recent($display);
+    return $block;
+
+  case 'recent_user':
+    if (arg(0) != 'user' && !is_numeric(arg(1))) {
       return $block;
     }
-    switch ($delta) {
-      case 'recent':
-        $display = variable_get('drupalvb_block_recent_type', 'threads');
-        $block['subject'] = ($display == 'threads' ? t('Recent forum threads') : t('Recent forum posts'));
-        $block['content'] = drupalvb_block_recent($display);
-        return $block;
-
-      case 'recent_user':
-        if (arg(0) != 'user' && !is_numeric(arg(1))) {
-          return $block;
-        }
-        $account = user_load(array('uid' => arg(1)));
-        $block['subject'] = t('Recent forum posts by %name', array('%name' => $account->name));
-        $block['content'] = drupalvb_block_recent_user($account);
-        return $block;
-
-      case 'top_posters':
-        $block['subject'] = t('Top forum posters');
-        $block['content'] = drupalvb_block_top_posters();
-        return $block;
-
-      case 'user':
-        if (!user_access('access content') || $user->uid < 1) {
-          return $block;
-        }
-        $block['subject'] = t('Forum info');
-        $block['content'] = drupalvb_block_info();
-        return $block;
-
-      case 'stats':
-        $block['subject'] = t('Forum statistics');
-        $block['content'] = drupalvb_block_stats();
-        return $block;
+    $account = user_load(arg(1));
+    $block['subject'] = t('Recent forum posts by %name', array('%name' => $account->name));
+    $block['content'] = drupalvb_block_recent_user($account);
+    return $block;
+
+  case 'top_posters':
+    $block['subject'] = t('Top forum posters');
+    $block['content'] = drupalvb_block_top_posters();
+    return $block;
+
+  case 'user':
+    global $user;
+    if (!user_access('access content') || $user->uid < 1) {
+      return $block;
     }
+    $block['subject'] = t('Forum info');
+    $block['content'] = drupalvb_block_user_info();
+    return $block;
+
+  case 'stats':
+    $block['subject'] = t('Forum statistics');
+    $block['content'] = drupalvb_block_stats();
+    return $block;
   }
 }
 
@@ -701,15 +696,15 @@ function drupalvb_block_recent($display) {
   $vb_options = drupalvb_get('options');
   switch ($display) {
     case 'threads':
-      $result = drupalvb_db_query("SELECT t.threadid, t.title, t.replycount, t.dateline AS created, t.postuserid AS userid, t.postusername AS name FROM {thread} t INNER JOIN {forum} f ON f.forumid = t.forumid WHERE f.showprivate = 0 AND t.lastpost >= %d ORDER BY t.dateline DESC LIMIT %d", $date_cut, $num_items);
+      $result = drupalvb_db_query("SELECT t.threadid, t.title, t.replycount, t.dateline AS created, t.postuserid AS userid, t.postusername AS name FROM {thread} t INNER JOIN {forum} f ON f.forumid = t.forumid WHERE f.showprivate = 0 AND t.lastpost >= :date ORDER BY t.dateline DESC LIMIT 5", array(":date" => $date_cut));
       break;
 
     case 'posts':
-      $result = drupalvb_db_query("SELECT p.postid, p.title, p.threadid, p.dateline AS created, p.userid, p.username AS name, t.title AS threadtitle FROM {post} p LEFT JOIN {thread} t ON p.threadid = t.threadid WHERE p.dateline >= %d ORDER BY p.dateline DESC LIMIT %d", $date_cut, $num_items);
+      $result = drupalvb_db_query("SELECT p.postid, p.title, p.threadid, p.dateline AS created, p.userid, p.username AS name, t.title AS threadtitle FROM {post} p LEFT JOIN {thread} t ON p.threadid = t.threadid WHERE p.dateline >= :date ORDER BY p.dateline DESC LIMIT :number", array(":date" => $date_cut, ":number" => $num_items));
       break;
   }
   $items = $userids = array();
-  while ($data = db_fetch_array($result)) {
+  while ($data = $result->fetchAssoc()) {
     if ($data['title'] == '') {
       $data['title'] = t('Re:') .' '. $data['threadtitle'];
     }
@@ -729,13 +724,13 @@ function drupalvb_block_recent($display) {
   // theme_drupalvb_username() takes care of that.
   if ($userids) {
     $result = db_query("SELECT d.userid, d.uid, u.picture FROM {drupalvb_users} d INNER JOIN {users} u ON u.uid = d.uid WHERE d.userid IN (". implode(',', array_keys($userids)) .")");
-    while ($data = db_fetch_array($result)) {
+    while ($data = $result->fetchAssoc()) {
       foreach ($userids[$data['userid']] as $i) {
         $items[$i] = array_merge($items[$i], $data);
       }
     }
   }
-  return theme('drupalvb_block_recent', $items, $vb_options);
+  return theme('drupalvb_block_recent', array("recent" => $items, "vb_options" => $vb_options));
 }
 
 /**
@@ -743,14 +738,16 @@ function drupalvb_block_recent($display) {
  *
  * @todo Unused $recent['replycount'] for threads.
  */
-function theme_drupalvb_block_recent($recent, $vb_options) {
+function theme_drupalvb_block_recent($variables) {
+  $recent = $variables['recent'];
+  $vb_options = $variables['vb_options'];
   $items = array();
-  $display_authors = variable_get('drupalvb_block_recent_authors', 0);
+  $display_authors = variable_get('drupalvb_block_recent_authors', 1);
   foreach ($recent as $item) {
-    $link = l($item['title'], $item['url'], array('query' => $item['query'], 'fragment' => $item['fragment']));
-    $items[] = ($display_authors ? t('!title <span>by !name</span>', array('!title' => $link, '!name' => theme('drupalvb_username', (object)$item))) : $link);
+    $link = l($item['title'], $item['url']."?".$item['query']);
+    $items[] = ($display_authors ? t('!title <span>by !name</span>', array('!title' => $link, '!name' => theme('drupalvb_username', array("object"=>$item)))) : $link);
   }
-  $output = theme('item_list', $items);
+  $output = theme('item_list', array("items" => $items));
   $output .= '<div class="forum-link">'. l(t('Visit the forum'), $vb_options['bburl']) .'</div>';
   return $output;
 }
@@ -759,25 +756,26 @@ function theme_drupalvb_block_recent($recent, $vb_options) {
  * Build data for recent posts by user block.
  */
 function drupalvb_block_recent_user($account) {
-  if ($vbuserid = db_result(db_query("SELECT userid FROM {drupalvb_users} WHERE uid = %d", $account->uid))) {
+  if ($vbuserid = db_query("SELECT userid FROM {drupalvb_users} WHERE uid = :uid", array(":uid" => $account->uid))->fetchField()) {
     $num_items  = variable_get('drupalvb_block_recent_count', 5);
     $vb_options = drupalvb_get('options');
-    $result = drupalvb_db_query("SELECT p.postid, p.title, p.threadid, p.dateline AS created, p.userid, p.username AS name, t.title AS threadtitle, p.pagetext AS body FROM {post} p INNER JOIN {thread} t ON p.threadid = t.threadid INNER JOIN {forum} f ON f.forumid = t.forumid WHERE f.showprivate = 0 AND p.userid = %d GROUP BY p.threadid ORDER BY p.dateline DESC LIMIT %d", $vbuserid, $num_items);
+    $result = drupalvb_db_query("SELECT p.postid, p.title, p.threadid, p.dateline AS created, p.userid, p.username AS name, t.title AS threadtitle, p.pagetext AS body FROM {post} p INNER JOIN {thread} t ON p.threadid = t.threadid INNER JOIN {forum} f ON f.forumid = t.forumid WHERE f.showprivate = 0 AND p.userid = :userid GROUP BY p.threadid ORDER BY p.dateline DESC LIMIT ".$num_items, array(":userid" => $vbuserid));
     $items = array();
-    while ($data = db_fetch_array($result)) {
+    while ($data = $result->fetchAssoc()) {
       if ($data['title'] == '') {
         // $data['title'] = t('Re:') .' '. $data['threadtitle'];
         $data['body'] = preg_replace('@\[ [^\]]+ \]@x', '', $data['body']);
         $data['title'] = truncate_utf8($data['body'], 80);
       }
+
       $data['title'] = decode_entities($data['title']);
       $data['threadtitle'] = decode_entities($data['threadtitle']);
       $data['url'] = $vb_options['bburl'] .'/showthread.php';
-      $data['query'] = 't='. $data['threadid'];
+      $data['query'] = array('t' =>$data['threadid']);
       $data['fragment'] = (isset($data['postid']) ? $data['postid'] : NULL);
       $items[$data['postid']] = $data;
     }
-    return theme('drupalvb_block_recent_user', $items, $vb_options);
+    return theme('drupalvb_block_recent_user', array("recent" => $items, "vb_options" => $vb_options));
   }
 }
 
@@ -786,14 +784,20 @@ function drupalvb_block_recent_user($account) {
  *
  * @todo Unused $recent['replycount'] for threads.
  */
-function theme_drupalvb_block_recent_user($recent, $vb_options) {
+function theme_drupalvb_block_recent_user($variables) {
   $items = array();
+  $recent = $variables['recent'];
+  $vb_options = $variables['vb_options'];
   foreach ($recent as $item) {
     $link_post = l($item['title'], $item['url'], array('query' => $item['query'], 'fragment' => $item['fragment']));
     $link_thread = l($item['threadtitle'], $item['url'], array('query' => $item['query']));
     $items[] = t('<span class="drupalvb-post">!title</span> <span class="drupalvb-thread">Thread: !thread</span>', array('!title' => $link_post, '!thread' => $link_thread));
   }
-  return theme('item_list', $items);
+
+  $variables = array(
+    "items" => $items,
+  );
+  return theme('item_list', $variables);
 }
 
 /**
@@ -802,16 +806,20 @@ function theme_drupalvb_block_recent_user($recent, $vb_options) {
 function drupalvb_block_top_posters() {
   $items = array();
   $num_items = variable_get('drupalvb_block_recent_count', 5);
-  $result = drupalvb_db_query_range("SELECT posts AS count, userid, username AS name FROM {user} ORDER BY posts DESC", 0, $num_items);
-  while ($data = db_fetch_array($result)) {
+  $result = drupalvb_db_query_range("SELECT posts AS count, userid, username AS name FROM {user} ORDER BY posts DESC", array(), 0, $num_items, array());
+  while ($data = $result->fetchAssoc()) {
     $items[$data['userid']] = $data;
   }
 
   $result = db_query("SELECT d.userid, d.uid, u.picture FROM {drupalvb_users} d INNER JOIN {users} u ON u.uid = d.uid WHERE d.userid IN (". implode(',', array_keys($items)) .")");
-  while ($data = db_fetch_array($result)) {
+  while ($data = $result->fetchAssoc()) {
     $items[$data['userid']] = array_merge($items[$data['userid']], $data);
   }
-  return theme('drupalvb_block_top_posters', $items);
+
+  $variables = array(
+    "items" => $items,
+  );
+  return theme('drupalvb_block_top_posters', $variables);
 }
 
 /**
@@ -820,18 +828,20 @@ function drupalvb_block_top_posters() {
  * @param $items
  *   An array of users.
  */
-function theme_drupalvb_block_top_posters($items) {
+function theme_drupalvb_block_top_posters($variables) {
+  $items = $variables['items'];
   foreach ($items as $key => $item) {
-    $items[$key] = theme('drupalvb_username', (object)$item, 'custom_toplist_posts') .' <span class="count">'. format_plural($item['count'], 'wrote <span>1 post</span>', 'wrote <span>@count posts</span>') .'</span>';
+    $items[$key] = theme('drupalvb_username', array("object" => $item), 'custom_toplist_posts') .' <span class="count">'. format_plural($item['count'], 'wrote <span>1 post</span>', 'wrote <span>@count posts</span>') .'</span>';
   }
-  return theme('item_list', $items);
+  return theme('item_list', array("items"=>$items));
 }
 
 /**
  * Build contents for the forum user info block.
  */
-function drupalvb_block_info() {
+function drupalvb_block_user_info() {
   global $user;
+  module_load_include('inc', 'drupalvb');
 
   $vb_options = drupalvb_get('options');
   $display = variable_get('drupalvb_block_user', drupal_map_assoc(array('online', 'recent', 'newposts', 'pms')));
@@ -860,13 +870,17 @@ function drupalvb_block_info() {
     );
   }
   if ($display['pms']) {
-    $vbuser = db_fetch_array(drupalvb_db_query("SELECT pmtotal, pmunread FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($user->name)));
+    $vbuser = drupalvb_db_query("SELECT pmtotal, pmunread FROM {user} WHERE username = :name", array(":name" => drupalvb_htmlspecialchars($user->name)))->fetchAssoc();
     $rows[] = array(
       l(t('New private messages'), 'drupalvb/pms'),
       (int)$vbuser['pmunread'],
     );
   }
-  return theme('table', $header, $rows);
+  $variables = array(
+    "header" => $header,
+    "rows" => $rows,
+  );
+  return theme('table', $variables);
 }
 
 /**
@@ -876,13 +890,13 @@ function drupalvb_block_stats() {
   // Get total threads & posts.
   $totalthreads = $totalposts = 0;
   $result = drupalvb_db_query("SELECT forumid, title, threadcount, replycount FROM {forum}");
-  while ($forum = db_fetch_array($result)) {
+  while ($forum = $result->fetchAssoc()) {
     $totalthreads += $forum['threadcount'];
     $totalposts += $forum['replycount'];
   }
   // Get user statistics.
   $result = drupalvb_db_query("SELECT data FROM {datastore} WHERE title = 'userstats'");
-  $data = db_fetch_array($result);
+  $data = $result->fetchAssoc();
   $userstats = unserialize($data['data']);
   $display = variable_get('drupalvb_block_stats', array('threads' => '1', 'posts' => '1', 'tmembers' => '1', 'amembers' => '1'));
 
@@ -899,7 +913,11 @@ function drupalvb_block_stats() {
   if ($display['amembers']) {
     $rows[] = array(t('Active Members:'), $userstats['activemembers']);
   }
-  return theme('table', array(), $rows);
+
+  $variables = array(
+    "rows" => $rows,
+  );
+  return theme('table', $variables);
 }
 
 /**
@@ -911,10 +929,12 @@ function drupalvb_block_stats() {
  * @param $class
  *   A class name for User Display API.
  */
-function theme_drupalvb_username($object, $class = NULL) {
+function theme_drupalvb_username($variables) {
+  $object = (object)$variables['object'];
+  $class = $variables['class'];
   if ($object && !empty($object->uid) && $object->name) {
     // Drupal account exists: fall back on default theming.
-    $output = theme('username', $object, $class);
+    $output = theme('username', array("account" => user_load($object->uid)));
   }
   else if ($object && !empty($object->userid) && $object->name) {
     // Remove any html entities injected by vBulletin.
@@ -1029,12 +1049,12 @@ function drupalvb_lookup_drupal_user($userid) {
   module_load_include('inc', 'drupalvb');
 
   // Check if this vBulletin user id already exists as Drupal user.
-  if ($uid = drupalvb_user_load($userid)) {
+  if ($uid = drupalvb_vb_user_load($userid)) {
     return $uid;
   }
 
   // Try to lookup the user id in the vBulletin database.
-  if ($vbuser = db_fetch_array(drupalvb_db_query("SELECT userid, username, email, joindate FROM {user} WHERE userid = %d", $userid))) {
+  if ($vbuser = drupalvb_db_query("SELECT userid, username, email, joindate FROM {user} WHERE userid = :userid", array(":userid"=>$userid))->fetchAssoc()) {
     // Register this user in Drupal using a temporary password, since we don't
     // know the real one. It will be updated when the user logs in to Drupal
     // for the first time using its vBulletin credentials.
@@ -1063,7 +1083,7 @@ function drupalvb_lookup_drupal_user($userid) {
       return $user->uid;
     }
     // In case the user couldn't be registered, try to load it from the database.
-    else if ($uid = drupalvb_user_load($vbuser['userid'])) {
+    else if ($uid = drupalvb_vb_user_load($vbuser['userid'])) {
       return $uid;
     }
     // We're out of luck...
@@ -1097,8 +1117,8 @@ function drupalvb_privatemsg($message, $op) {
   switch ($op) {
     case 'sent':
       // Verify that recipient exists in vB.
-      $recipient = user_load(array('uid' => $message->recipient));
-      if (!$userid = db_result(drupalvb_db_query_range("SELECT userid FROM {user} WHERE username = '%s'", drupalvb_htmlspecialchars($recipient->name), 0, 1))) {
+      $recipient = user_load($message->recipient);
+      if (!$userid = drupalvb_db_query_range("SELECT userid FROM {user} WHERE username = :name", array(":name" => drupalvb_htmlspecialchars($recipient->name)), 0, 1)->fetchField()) {
         if (!$userid = drupalvb_create_user($recipient, (array)$recipient)) {
           // Indicates duplicate username (should not happen).
           return;
