diff --git a/clippedme.module b/clippedme.module
index 42edc7c..e17956d 100644
--- a/clippedme.module
+++ b/clippedme.module
@@ -29,24 +29,29 @@ function clippedme_menu() {
 }
 
 /**
- * Implements hook_init().
+ * Implements hook_page_alter().
  */
-function clippedme_init() {
-  $plugin_path = libraries_get_path('poshy_tip');
-  drupal_add_js($plugin_path . '/src/jquery.poshytip.min.js', 'file');
+function clippedme_page_alter(&$page) {
   $theme = variable_get('clippedme_theme', 'tip-clippedme');
+  $plugin_path = libraries_get_path('poshy_tip');
   if ($theme == 'tip-clippedme') {
-    drupal_add_css(drupal_get_path('module', 'clippedme') . '/assets/tip-clippedme.css', 'file');
+    $page['content']['#attached']['css'][] = drupal_get_path('module', 'clippedme') . '/assets/tip-clippedme.css';
   }
   elseif ($theme != 'tip-custom') {
-    drupal_add_css($plugin_path . '/src/' . $theme . '/' . $theme . '.css', 'file');
+    $page['content']['#attached']['css'][] = $plugin_path . '/src/' . $theme . '/' . $theme . '.css';
   }
-  drupal_add_js(array('clippedMe' => array('theme' => $theme)), 'setting');
-  drupal_add_js(drupal_get_path('module', 'clippedme') . '/assets/clippedme.js', 'file');
-  // Pass target class name.
-  drupal_add_js(array('clippedMe' => array('selector' => variable_get('clippedme_selector', 'clippedme'))), 'setting');
-  // Pass URLs of branding images.
-  clippedme_branding();
+  $page['content']['#attached']['js'][] = $plugin_path . '/src/jquery.poshytip.min.js';
+  $page['content']['#attached']['js'][] = drupal_get_path('module', 'clippedme') . '/assets/clippedme.js';
+  $page['content']['system_main']['#attached']['js'][] = array(
+    'type' => 'setting',
+    'data' => array(
+      'clippedMe' => array(
+        'branding' => file_create_url(drupal_get_path('module', 'clippedme') . '/assets/clipped.png'),
+        'selector' => variable_get('clippedme_selector', 'clippedme'),
+        'theme' => $theme,
+      ),
+    ),
+  );
 }
 
 /**
@@ -87,16 +92,6 @@ function clippedme_get_data($path) {
 }
 
 /**
- * Helper function - pass Clipped.me branding as a js setting.
- */
-function clippedme_branding() {
-  global $base_url;
-  // URL of Clipped logo.
-  $img = $base_url . '/' . drupal_get_path('module', 'clippedme') . '/assets/clipped.png';
-  drupal_add_js(array('clippedMe' => array('branding' => $img)), 'setting');
-}
-
-/**
  * Page callback for the 'local proxy' to work around same origin policy.
  *
  * This acts as a proxy between jQuery and clippedme_get_data(). URL is passed
@@ -105,12 +100,14 @@ function clippedme_branding() {
 function clippedme_proxy() {
   // Deny access to peekers.
   if (parse_url($_SERVER['HTTP_REFERER'], PHP_URL_HOST) !== $_SERVER['HTTP_HOST']) {
-    drupal_access_denied();
+    drupal_add_http_header('Status', '403 Forbidden');
+    drupal_exit();
   }
   // No URL, no results.
-  if (empty($_GET['url'])) {
-    print drupal_json_encode(array('error' => 'no_url'));
-    exit;
+  if (!empty($_GET['url'])) {
+    drupal_add_http_header('Status', '404 Not Found');
+    drupal_json_output(array('error' => 'no_url'));
+    drupal_exit();
   }
   if (url_is_external($_GET['url'])) {
     $path = $_GET['url'];
@@ -118,6 +115,6 @@ function clippedme_proxy() {
   else {
     $path = $GLOBALS['base_url'] . '/' . $_GET['url'];
   }
-  print drupal_json_encode(array_values(clippedme_get_data($path)));
-  exit;
+  drupal_json_output(array_values(clippedme_get_data($path)));
+  drupal_exit();
 }
