diff --git a/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic.php b/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic.php
index 6649c41..ebeec0b 100644
--- a/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic.php
+++ b/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic.php
@@ -22,9 +22,15 @@ public function incrementDisplayCount($bannerId)
         $row = $this->_getReadAdapter()->fetchRow($select);
 
         if ($row) {
-            $this->_getWriteAdapter()->update($this->getMainTable(), array(
-                'display_count' => ++$row['display_count']
-                ), "banner_id = {$bannerId} AND date = '{$todayDate}'"
+            $this->_getWriteAdapter()->update(
+                $this->getMainTable(),
+                array(
+                    'display_count' => ++$row['display_count']
+                ),
+                array(
+                    'banner_id = ?' => $bannerId,
+                    'date = ?' => $todayDate
+                )
             );
         } else {
             $this->_getWriteAdapter()->insert($this->getMainTable(), array(
@@ -51,9 +57,15 @@ public function incrementClicksCount($bannerId)
         $row = $this->_getReadAdapter()->fetchRow($select);
 
         if ($row) {
-            $this->_getWriteAdapter()->update($this->getMainTable(), array(
-                'clicks_count' => ++$row['clicks_count']
-                ), "banner_id = {$bannerId} AND date = '{$todayDate}'"
+            $this->_getWriteAdapter()->update(
+                $this->getMainTable(),
+                array(
+                    'clicks_count' => ++$row['clicks_count']
+                ),
+                array(
+                    'banner_id = ?' => $bannerId,
+                    'date = ?' => $todayDate
+                )
             );
         } else {
             // if banner was rendered at 23:59 and clicked at 00:01
diff --git a/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic/Aggregated.php b/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic/Aggregated.php
index 3bb36b4..2603929 100644
--- a/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic/Aggregated.php
+++ b/app/code/local/TM/EasyBanner/Model/Mysql4/Banner/Statistic/Aggregated.php
@@ -16,9 +16,14 @@ public function incrementDisplayCount($bannerId)
         $row = $this->_getReadAdapter()->fetchRow($select);
 
         if ($row) {
-            $this->_getWriteAdapter()->update($this->getMainTable(), array(
-                'display_count' => ++$row['display_count']
-                ), "banner_id = {$bannerId}"
+            $this->_getWriteAdapter()->update(
+                $this->getMainTable(),
+                array(
+                    'display_count' => ++$row['display_count']
+                ),
+                array(
+                    'banner_id = ?' => $bannerId
+                )
             );
         } else {
             $this->_getWriteAdapter()->insert($this->getMainTable(), array(
@@ -38,9 +43,14 @@ public function incrementClicksCount($bannerId)
         $row = $this->_getReadAdapter()->fetchRow($select);
 
         if ($row) {
-            $this->_getWriteAdapter()->update($this->getMainTable(), array(
-                'clicks_count' => ++$row['clicks_count']
-                ), "banner_id = {$bannerId}"
+            $this->_getWriteAdapter()->update(
+                $this->getMainTable(),
+                array(
+                    'clicks_count' => ++$row['clicks_count']
+                ),
+                array(
+                    'banner_id = ?' => $bannerId
+                )
             );
         } else {
             $this->_getWriteAdapter()->insert($this->getMainTable(), array(
diff --git a/app/code/local/TM/EasyBanner/controllers/IndexController.php b/app/code/local/TM/EasyBanner/controllers/IndexController.php
index 87d0ba1..bde50ad 100644
--- a/app/code/local/TM/EasyBanner/controllers/IndexController.php
+++ b/app/code/local/TM/EasyBanner/controllers/IndexController.php
@@ -7,34 +7,38 @@ class TM_EasyBanner_IndexController extends Mage_Core_Controller_Front_Action
      */
     public function clickAction()
     {
-        $bannerId = $this->getRequest()->getParam('banner_id', false);
+        $bannerId = (int) $this->getRequest()->getParam('banner_id', false);
+        if (!$bannerId) {
+            return $this->_forward('noRoute');
+        }
+
         $model = Mage::getModel('easybanner/banner')->load($bannerId);
-        if (!$bannerId || !$model->check(Mage::app()->getStore()->getId())) {
-            $this->_forward('noRoute');
-        } else {
-            Mage::dispatchEvent('tm_easybanner_banner_click', array(
-                'banner_id' => $bannerId
-            ));
-
-            $redirectUrl = $model->getUrl();
-
-            if (strpos($redirectUrl, 'www.') === 0) {
-                $redirectUrl = 'http://' . $model->getUrl();
-            } elseif (strpos($redirectUrl, 'http://') !== 0
-                && strpos($redirectUrl, 'https://') !== 0) {
-
-                // trim leading slashes to get correct redirect URL
-                $redirectUrl = ltrim($redirectUrl, '/');
-
-                if (strpos($redirectUrl, '.html') !== false) {
-                    // hotfix for seo links.
-                    $redirectUrl = Mage::getModel('core/url')->getDirectUrl($redirectUrl);
-                } else {
-                    $redirectUrl = Mage::getUrl($redirectUrl);
-                }
-            }
+        if (!$model->getId() || !$model->check(Mage::app()->getStore()->getId())) {
+            return $this->_forward('noRoute');
+        }
+
+        Mage::dispatchEvent('tm_easybanner_banner_click', array(
+            'banner_id' => $model->getId()
+        ));
 
-            $this->getResponse()->setRedirect($redirectUrl);
+        $redirectUrl = $model->getUrl();
+
+        if (strpos($redirectUrl, 'www.') === 0) {
+            $redirectUrl = 'http://' . $model->getUrl();
+        } elseif (strpos($redirectUrl, 'http://') !== 0
+            && strpos($redirectUrl, 'https://') !== 0) {
+
+            // trim leading slashes to get correct redirect URL
+            $redirectUrl = ltrim($redirectUrl, '/');
+
+            if (strpos($redirectUrl, '.html') !== false) {
+                // hotfix for seo links.
+                $redirectUrl = Mage::getModel('core/url')->getDirectUrl($redirectUrl);
+            } else {
+                $redirectUrl = Mage::getUrl($redirectUrl);
+            }
         }
+
+        $this->getResponse()->setRedirect($redirectUrl);
     }
 }
