diff --git a/chatroom.forms.inc b/chatroom.forms.inc
index 2252caf..f9e1050 100644
--- a/chatroom.forms.inc
+++ b/chatroom.forms.inc
@@ -110,7 +110,7 @@ function chatroom_form(&$node, $form_state) {
     '#size' => 5,
   );
   $old_msg_range = array();
-  for ($i = 1; $i <= 25; $i++) {
+  for ($i = 0; $i <= 25; $i++) {
     $old_msg_range[$i] = $i * 10;
   }
   $form['chat_settings']['previous_messages_display_count'] = array(
@@ -419,7 +419,7 @@ function chatroom_chat_form(&$node, $form_state) {
     '#size' => 5,
   );
   $previous_msg_range = array();
-  for ($i = 1; $i <= 25; $i++) {
+  for ($i = 0; $i <= 25; $i++) {
     $previous_msg_range[$i] = $i * 10;
   }
   $form['chat_settings']['previous_messages_display_count'] = array(
diff --git a/chatroom.js b/chatroom.js
index a2a48c2..9a56e72 100644
--- a/chatroom.js
+++ b/chatroom.js
@@ -9,7 +9,11 @@ $(document).ready(function () {
   Drupal.settings.chatroom.pageTitle = document.title;
   Drupal.settings.chatroom.hasFocus = true;
   if (Drupal.settings.chatroom.latestMsgId > 0) {
-    var targetOffset = $('div.new-message:last').offset().top;
+    var targetOffset = 0;
+    var lastNewMessage = $('div.new-message:last');
+    if (lastNewMessage && lastNewMessage.offset()) {
+        targetOffset = lastNewMessage.top;
+    }
     var boardOffset = $('#chatroom-board').offset().top;
     var scrollAmount = targetOffset - boardOffset;
     $('#chatroom-board').animate({scrollTop: '+='+ scrollAmount +'px'}, 500);
