diff --git a/twitter_search.info b/twitter_search.info
index 235a5e3..1c2caa1 100644
--- a/twitter_search.info
+++ b/twitter_search.info
@@ -1,5 +1,4 @@
 name = Twitter search
 description = Adds search functionality to the Twitter module.
-php = 5.2
-core = 6.x
+core = 7.x
 dependencies[] = twitter
diff --git a/twitter_search.install b/twitter_search.install
index 325fbb2..ffa5e96 100644
--- a/twitter_search.install
+++ b/twitter_search.install
@@ -1,36 +1,41 @@
 <?php
+/**
+ * @file
+ * Install, update and uninstall functions for the twitter_search module.
+ */
+
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function twitter_search_schema() {
   $schema['twitter_search'] = array(
-    'description' => t('Stores Twitter search strings.'),
+    'description' => 'Stores Twitter search strings.',
     'fields' => array(
       'twitter_search_id' => array(
-        'description' => t('Unique identifier for each {twitter_search} string.'),
+        'description' => 'Unique identifier for each {twitter_search} string.',
         'type' => 'serial',
         'unsigned' => TRUE,
         'not null' => TRUE,
       ),
       'search' => array(
-        'description' => t('Search string to query Twitter for.'),
+        'description' => 'Search string to query Twitter for.',
         'type' => 'varchar',
         'length' => 140,
         'not null' => TRUE,
-        'default' => ''
+        'default' => '',
       ),
       'last_twitter_id' => array(
-        'description' => t('Unique identifier for the latest {twitter} post for this search.'),
+        'description' => 'Unique identifier for the latest {twitter} post for this search.',
         'type' => 'numeric',
         'unsigned' => TRUE,
         'precision' => 20,
         'scale' => 0,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
       'last_refresh' => array(
-        'description' => t('A UNIX timestamp marking the date Twitter statuses were last fetched on.'),
+        'description' => 'A UNIX timestamp marking the date Twitter statuses were last fetched on.',
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
@@ -40,23 +45,23 @@ function twitter_search_schema() {
   );
 
   $schema['twitter_search_tweet'] = array(
-    'description' => t('Maps {twitter} posts to specific searches.'),
+    'description' => 'Maps {twitter} posts to specific searches.',
     'fields' => array(
       'twitter_search_id' => array(
-        'description' => t('Unique identifier for each {twitter_search} string.'),
+        'description' => 'Unique identifier for each {twitter_search} string.',
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default'  => 0,
+        'default' => 0,
       ),
       'twitter_id' => array(
-        'description' => t("Unique identifier for each {twitter} post."),
+        'description' => "Unique identifier for each {twitter} post.",
         'type' => 'numeric',
         'unsigned' => TRUE,
         'precision' => 20,
         'scale' => 0,
         'not null' => TRUE,
-        'default' => 0
+        'default' => 0,
       ),
     ),
   );
@@ -65,35 +70,36 @@ function twitter_search_schema() {
 }
 
 /**
- * Implementation of hook_install().
+ * Implements hook_install().
  */
 function twitter_search_install() {
   // Create tables.
-  drupal_install_schema('twitter_search');
-
   // Set the weight to 3, making it heavier than Pathauto.
-  db_query("UPDATE {system} SET weight = 3 WHERE name = 'twitter_search'");
+  db_update('system')
+    ->fields(array(
+        'weight' => 3,
+      ))
+    ->condition('type', 'module')
+    ->condition('name', 'twitter_search')
+    ->execute();
 }
 
 /**
- * Implementation of hook_uninstall().
+ * Implements hook_uninstall().
  */
 function twitter_search_uninstall() {
   // Remove tables.
-  drupal_uninstall_schema('twitter_search');
-
-  // Delete settings from varible table.
-  $sql = "DELETE FROM {variable}
-          WHERE name LIKE 'twitter_search_%'";
-  db_query($sql);
+  // Delete settings from variable table.
+  db_delete('variable')
+    ->condition('name', 'twitter_search_%', 'LIKE')
+    ->execute();
 }
 
 /**
- * Implementation of hook_update_NNNN().
+ * Implements hook_update_NNNN().
  */
 function twitter_search_update_6001() {
   $ret = array();
-  db_drop_primary_key($ret, 'twitter_search_statuses');
-  db_rename_table($ret, 'twitter_search_statuses', 'twitter_search_tweet');
-  return $ret;
+  db_drop_primary_key('twitter_search_statuses');
+  db_rename_table('twitter_search_statuses', 'twitter_search_tweet');
 }
diff --git a/twitter_search.module b/twitter_search.module
index 7b29325..1f8af93 100644
--- a/twitter_search.module
+++ b/twitter_search.module
@@ -2,43 +2,48 @@
 
 /**
  * @file
- *  Adds search API features to the Twitter module.
+ * Adds search API features to the Twitter module.
  */
 
 /**
- * Implementation of hook_perm().
+ * Implements hook_permission().
  */
-function twitter_search_perm() {
-  return array('administer twitter search');
+function twitter_search_permission() {
+  return array(
+    'administer twitter search' => array(
+      'title' => t('administer twitter search'),
+      'description' => t('Administer twitter search'),
+    ),
+  );
 }
 
 /**
- * Implementation of hook_views_api().
- *
+ * Implements hook_views_api().
  */
 function twitter_search_views_api() {
   return array('api' => '2.0');
 }
 
 /**
- * Implementation of hook_menu().
+ * Implements hook_menu().
  */
 function twitter_search_menu() {
   $items = array();
-	$items['admin/settings/twitter_search'] = array(
-		'title' => 'Twitter search',
-		'description' => 'Settings for the site\'s Twitter search integration.',
-		'page callback' => 'twitter_search_list_page',
-		'type' => MENU_NORMAL_ITEM,
-		'access arguments' => array('administer twitter search'),
+
+  $items['admin/config/services/twitter/twitter_search'] = array(
+    'title' => 'Twitter search',
+    'description' => 'Settings for the site\'s Twitter search integration.',
+    'page callback' => 'twitter_search_list_page',
+    'type' => MENU_LOCAL_TASK,
+    'access arguments' => array('administer twitter search'),
     'file' => 'twitter_search.pages.inc',
-	);
-  $items['admin/settings/twitter_search/list'] = array(
+  );
+  $items['admin/config/services/twitter/twitter_search/list'] = array(
     'title' => 'List',
     'type' => MENU_DEFAULT_LOCAL_TASK,
     'weight' => -25,
   );
-  $items['admin/settings/twitter_search/add'] = array(
+  $items['admin/config/services/twitter/twitter_search/add'] = array(
     'title' => 'Add Twitter search text',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('twitter_search_add_form'),
@@ -46,7 +51,7 @@ function twitter_search_menu() {
     'access arguments' => array('administer twitter search'),
     'file' => 'twitter_search.pages.inc',
   );
-  $items['admin/settings/twitter_search/delete/%'] = array(
+  $items['admin/config/services/twitter/twitter_search/delete/%'] = array(
     'title' => 'Delete Twitter search text',
     'page callback' => 'drupal_get_form',
     'page arguments' => array('twitter_search_delete_confirm'),
@@ -54,12 +59,12 @@ function twitter_search_menu() {
     'access arguments' => array('administer twitter search'),
     'file' => 'twitter_search.pages.inc',
   );
-	return $items;
+  return $items;
 }
 
 
 /**
- * Implementation of hook_cron()
+ * Implements hook_cron().
  *
  * Imports new Twitter search statuses for site searches.
  */
@@ -67,28 +72,40 @@ function twitter_search_cron() {
   if (!variable_get('twitter_import', TRUE)) {
     return;
   }
-
   module_load_include('inc', 'twitter');
+  // Check if we can connect to Twitter before proceeding.
+  $twitter = twitter_connect();
+  if (!$twitter) {
+    return;
+  }
 
   // Get a list of search strings to update.
   $sql = "SELECT twitter_search_id, search, last_twitter_id
           FROM {twitter_search}
           ORDER BY last_refresh";
-  $results = db_query_range($sql, 0, 20);
-
-  while ($search = db_fetch_array($results)) {
-    $statuses = twitter_search_fetch_search($search);
-
-    if (!empty($statuses)) {
-      // Store last time search was fetched so that we grab new searches
-      // first. Also store the last twitter id for each search so that we only
-      // pull updated tweets.
-      $sql = "UPDATE {twitter_search}
-              SET last_twitter_id = %n, last_refresh = %d
-              WHERE search = '%s'";
-      db_query($sql, $statuses[0]['twitter_id'], $_SERVER['REQUEST_TIME'], $search['search']);
+  $results = db_query($sql);
+
+  try {
+    while ($search = $results->fetchAssoc()) {
+      $statuses = twitter_search_fetch_search($search['search']);
+      if (!empty($statuses)) {
+        // Store last time search was fetched so that we grab new searches
+        // first. Also store the last twitter id for each search so that we only
+        // pull updated tweets.
+        db_update('twitter_search')
+          ->fields(array(
+            'last_twitter_id' => $statuses[0]->twitter_id,
+            'last_refresh' => $_SERVER['REQUEST_TIME'],
+          ))
+          ->condition('search', $search['search'])
+          ->execute();
+      }
     }
   }
+  catch (TwitterException $e) {
+    // The exception has already been logged so we do not need to do
+    // anything here apart from caching it.
+  }
 }
 
 /**
@@ -96,80 +113,43 @@ function twitter_search_cron() {
  *
  * @see http://apiwiki.twitter.com/Twitter-Search-API-Method%3A+search
  *
- * @param $search
- *  Assoc array containing search string, search id, and last twitter id.
- * @param $cache
- *  Boolean. Whether or not to cache the Twitter statues.
+ * @param String $search
+ *   Assoc array containing search string, search id, and last twitter id.
+ *
+ * @return Boolean
+ *   Whether or not to cache the Twitter statues.
  */
-function twitter_search_fetch_search($search, $cache = TRUE) {
+function twitter_search_fetch_search($search) {
+  // Check if we can connect to Twitter before proceeding.
   module_load_include('inc', 'twitter');
-
-  $url = 'http://search.twitter.com/search.json?q=' . urlencode($search['search']);
-  if ($search['last_twitter_id']) {
-    $url .= '&since_id=' . $search['last_twitter_id'];
+  $twitter = twitter_connect();
+  if (!$twitter) {
+    return;
   }
-  $response = drupal_http_request($url, array(), 'GET');
 
-  if (_twitter_request_failure($response)) {
-    return array();
-  }
-  else {
-    // Process the response
-    $results = _twitter_search_convert_json_to_array($response->data);
-    if ($cache) {
-      foreach($results as $status) {
-        twitter_cache_status($status);
+  // Connect to the Twitter's API.
+  $twitter = twitter_connect();
+  $params = array();
 
-        // Store Twitter ID to map to searchs.
-        $row = array(
-          'twitter_id' => $status['twitter_id'],
-          'twitter_search_id' => $search['twitter_search_id'],
-        );
-        drupal_write_record('twitter_search_tweet', $row);
-      }
-    }
-    return $results;
+  // Fetch tweets.
+  $statuses = $twitter->search_tweets($search, $params);
+  foreach ($statuses as $status) {
+    twitter_status_save($status);
+    twitter_account_save($status->user);
   }
+  return $statuses;
 }
 
 /**
- * Internal JSON munging code.
+ * Tests whether search already exists.
+ *
+ * @param String $search
+ *   Assoc array containing search string, search id, and last twitter id.
  *
- * @param $data
- *  JSON string returned by Twitter.
+ * @return Boolean
+ *   Boolean. Whether or not to cache the Twitter statues.
  */
-function _twitter_search_convert_json_to_array($data) {
-  $results = array();
-  $json = json_decode($data);
-
-  if (!empty($json->results)) {
-    foreach($json->results as $status) {
-      $results[] = array(
-        'twitter_id' => $status->id,
-        'screen_name' => $status->from_user,
-        'created_at' => $status->created_at,
-        'created_time' => strtotime($status->created_at),
-        'text' => html_entity_decode($status->text),
-        'source' => html_entity_decode($status->source),
-        'in_reply_to_status_id' => isset($status->to_id) ? $status->to_id : NULL,
-        'in_reply_to_user_id' => $status->to_user_id,
-        'in_reply_to_screen_name' => isset($status->to_user) ? $status->to_user : NULL,
-        'truncated' => 0,
-      );
-
-      // If the screen name isn't already cached, save a partial user object with the tweet.
-      if (!db_result(db_query("SELECT * from {twitter} WHERE screen_name = '%s' LIMIT 1", $status->from_user))) {
-        $account = array(
-          'twitter_uid' => $status->from_user_id,
-          'screen_name' => $status->from_user,
-          'profile_image_url' => $status->profile_image_url,
-          'protected' => FALSE,
-          'last_refresh' => strtotime($status->created_at),
-        );
-        twitter_cache_account($account);
-      }
-    }
-  }
-
-  return $results;
+function twitter_search_already_exists($search) {
+  $result = db_query("SELECT search FROM {twitter_search} WHERE search = :search", array(':search' => $search))->fetchField();
+  return $result ? TRUE : FALSE;
 }
diff --git a/twitter_search.pages.inc b/twitter_search.pages.inc
index 251edb5..fb91b2b 100644
--- a/twitter_search.pages.inc
+++ b/twitter_search.pages.inc
@@ -1,32 +1,32 @@
 <?php
 /**
  * @file
- *  Administration pages and code for the Twitter search module.
+ * Administration pages and code for the Twitter search module.
  */
 
 /**
  * Lists search strings.
  *
- * @return
- *  Page HTML.
+ * @return String
+ *   Page HTML.
  */
 function twitter_search_list_page() {
   // Get search strings from database.
   $sql = "SELECT twitter_search_id, search
           FROM {twitter_search}
           ORDER BY last_refresh";
-  $results = db_query($sql);
 
+  $results = db_query($sql);
   $header = array(t('Search'), t('Operations'));
 
   $rows = array();
-  while ($search = db_fetch_array($results)) {
+
+  while ($search = $results->fetchAssoc()) {
     $rows[] = array(
       check_plain($search['search']),
-      array('data' => l(t('delete'), 'admin/settings/twitter_search/delete/' . $search['twitter_search_id'])),
+      array('data' => l(t('delete'), 'admin/config/services/twitter/twitter_search/delete/' . $search['twitter_search_id'])),
     );
   }
-
   if (empty($rows)) {
     $rows[] = array(
       array(
@@ -37,16 +37,16 @@ function twitter_search_list_page() {
     );
   }
 
-  return theme('table', $header, $rows);
+  return theme('table', array('header' => $header, 'rows' => $rows));
 }
 
 /**
  * Administration form.
  *
- * @return
- *  FAPI array.
+ * @return Array
+ *   FAPI array.
  */
-function twitter_search_add_form() {
+function twitter_search_add_form($form, &$form_state) {
   $form['search_string'] = array(
     '#type' => 'textfield',
     '#title' => t('Text to search Twitter for'),
@@ -70,8 +70,8 @@ function twitter_search_add_form() {
  *
  * @see twitter_search_add_form()
  *
- * @return
- *  FAPI array.
+ * @return Array
+ *   FAPI array.
  */
 function twitter_search_add_form_submit($form, &$form_state) {
   $search = array(
@@ -84,20 +84,22 @@ function twitter_search_add_form_submit($form, &$form_state) {
   drupal_write_record('twitter_search', $search);
 
   drupal_set_message(t('Twitter search text saved.'), 'status');
-  $form_state['redirect'] = 'admin/settings/twitter_search';
+  $form_state['redirect'] = 'admin/config/services/twitter/twitter_search';
   return;
 }
 
 /**
  * Menu callback; delete a single Twitter search.
  */
-function twitter_search_delete_confirm(&$form_state) {
+function twitter_search_delete_confirm($form, &$form_state) {
   $twitter_search_id = check_plain(arg(4));
 
   $sql = "SELECT search
           FROM {twitter_search}
           WHERE twitter_search_id = %d";
-  $search_string = db_result(db_query($sql, $twitter_search_id));
+  $search_string = db_query("SELECT search
+          FROM {twitter_search}
+          WHERE twitter_search_id = :twitter_search_id", array(':twitter_search_id' => $twitter_search_id))->fetchField();
 
   $form['twitter_search_id'] = array(
     '#type' => 'value',
@@ -109,13 +111,13 @@ function twitter_search_delete_confirm(&$form_state) {
   );
 
   $message = t('Are you sure you want to delete the Twitter search "%search"?', array('%search' => $search_string));
-  $caption = '<p>'. t('This action cannot be undone.') .'</p>';
+  $caption = '<p>' . t('This action cannot be undone.') . '</p>';
 
-  return confirm_form($form, $message, 'admin/settings/twitter_search', $caption, t('Delete'));
+  return confirm_form($form, $message, 'admin/config/services/twitter/twitter_search', $caption, t('Delete'));
 }
 
 /**
- * Delete confirm sumbit handler.
+ * Delete confirm submit handler.
  *
  * @see twitter_search_delete_confirm()
  */
@@ -123,12 +125,12 @@ function twitter_search_delete_confirm_submit($form, &$form_state) {
   $twitter_search_id = check_plain($form_state['values']['twitter_search_id']);
   $search_string = check_plain($form_state['values']['search_string']);
 
-  $sql = "DELETE FROM {twitter_search}
-          WHERE twitter_search_id = %d";
-  $result = db_query($sql, $twitter_search_id);
+  $result = db_delete('twitter_search')
+    ->condition('twitter_search_id', $twitter_search_id)
+    ->execute();
 
   drupal_set_message(t('The search "%search" has been deleted.', array('%search' => $search_string)));
 
-  $form_state['redirect'] = 'admin/settings/twitter_search';
+  $form_state['redirect'] = 'admin/config/services/twitter/twitter_search';
   return;
 }
diff --git a/twitter_search.views.inc b/twitter_search.views.inc
index 61bc378..6ea3f1f 100644
--- a/twitter_search.views.inc
+++ b/twitter_search.views.inc
@@ -1,16 +1,16 @@
 <?php
 /**
  * @file
- *  Provide views data and handlers.
+ * Provide views data and handlers.
  */
 
 /**
- * Implementation of hook_views_data().
+ * Implements hook_views_data().
  */
 function twitter_search_views_data() {
   $data = array();
 
-   $data['twitter_search'] = array(
+  $data['twitter_search'] = array(
     'twitter_search_id' => array(
       'title' => t('twitter_search_id'),
       'help' => t('Unique identifier for each {twitter_search} string.'),
@@ -146,7 +146,7 @@ function twitter_search_views_data() {
     'table' => array(
       'group' => t('Twitter: Search'),
       'join' => array(
-      'twitter_search' => array(
+        'twitter_search' => array(
           'left_field' => 'twitter_search_id',
           'field' => 'twitter_search_id',
         ),
