_network = network;
 
   connect(network, SIGNAL(networkNameSet(QString)),
-         this, SLOT(setNetworkName(QString)));
+          this, SLOT(setNetworkName(QString)));
   connect(network, SIGNAL(currentServerSet(QString)),
-         this, SLOT(setCurrentServer(QString)));
+          this, SLOT(setCurrentServer(QString)));
   connect(network, SIGNAL(ircChannelAdded(IrcChannel *)),
-         this, SLOT(attachIrcChannel(IrcChannel *)));
+          this, SLOT(attachIrcChannel(IrcChannel *)));
   connect(network, SIGNAL(ircUserAdded(IrcUser *)),
-         this, SLOT(attachIrcUser(IrcUser *)));
+          this, SLOT(attachIrcUser(IrcUser *)));
   connect(network, SIGNAL(connectedSet(bool)),
-         this, SIGNAL(networkDataChanged()));
+          this, SIGNAL(networkDataChanged()));
   connect(network, SIGNAL(destroyed()),
-         this, SIGNAL(networkDataChanged()));
+          this, SIGNAL(networkDataChanged()));
 
   emit networkDataChanged();
 }
     stateChanged = true;
     _firstUnreadMsgId = msg.msgId();
   }
-     
+
   BufferInfo::ActivityLevel oldLevel = activityLevel();
 
   _activity |= BufferInfo::OtherActivity;
     {
       QString newName = value.toString();
       if(!newName.isEmpty()) {
-       Client::renameBuffer(bufferId(), newName);
-       return true;
+        Client::renameBuffer(bufferId(), newName);
+        return true;
       } else {
-       return false;
+        return false;
       }
     }
     break;
       QString _topic = topic();
       if(_topic != "") {
         _topic = stripFormatCodes(_topic);
-       _topic = Qt::escape(_topic);
+        _topic = Qt::escape(_topic);
         toolTip.append(QString("<font size='-2'> </font>"));
         toolTip.append(tr("<b>Topic:</b> %1").arg(_topic));
       }
   _ircChannel = ircChannel;
 
   connect(ircChannel, SIGNAL(topicSet(QString)),
-         this, SLOT(setTopic(QString)));
+          this, SLOT(setTopic(QString)));
   connect(ircChannel, SIGNAL(ircUsersJoined(QList<IrcUser *>)),
-         this, SLOT(join(QList<IrcUser *>)));
+          this, SLOT(join(QList<IrcUser *>)));
   connect(ircChannel, SIGNAL(ircUserParted(IrcUser *)),
-         this, SLOT(part(IrcUser *)));
+          this, SLOT(part(IrcUser *)));
   connect(ircChannel, SIGNAL(parted()),
-         this, SLOT(ircChannelParted()));
+          this, SLOT(ircChannelParted()));
   connect(ircChannel, SIGNAL(ircUserModesSet(IrcUser *, QString)),
-         this, SLOT(userModeChanged(IrcUser *)));
+          this, SLOT(userModeChanged(IrcUser *)));
   connect(ircChannel, SIGNAL(ircUserModeAdded(IrcUser *, QString)),
-         this, SLOT(userModeChanged(IrcUser *)));
+          this, SLOT(userModeChanged(IrcUser *)));
   connect(ircChannel, SIGNAL(ircUserModeRemoved(IrcUser *, QString)),
-         this, SLOT(userModeChanged(IrcUser *)));
+          this, SLOT(userModeChanged(IrcUser *)));
 
   if(!ircChannel->ircUsers().isEmpty())
     join(ircChannel->ircUsers());
     categoryItem = qobject_cast<UserCategoryItem *>(child(i));
     if(categoryItem->removeUser(ircUser)) {
       if(categoryItem->childCount() == 0)
-       removeChild(i);
+        removeChild(i);
       break;
     }
   }
   : TreeModel(NetworkModel::defaultHeader(), parent)
 {
   connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
-         this, SLOT(checkForNewBuffers(const QModelIndex &, int, int)));
+          this, SLOT(checkForNewBuffers(const QModelIndex &, int, int)));
   connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
-         this, SLOT(checkForRemovedBuffers(const QModelIndex &, int, int)));
+          this, SLOT(checkForRemovedBuffers(const QModelIndex &, int, int)));
 
   BufferSettings defaultSettings;
   defaultSettings.notify("UserNoticesTarget", this, SLOT(messageRedirectionSettingsChanged()));
     if(bufferType(msg.bufferId()) != BufferInfo::ChannelBuffer) {
       msg.setFlags(msg.flags() | Message::Redirected);
       if(msg.flags() & Message::ServerMsg) {
-       // server notice
-       redirectionTarget = _serverNoticesTarget;
+        // server notice
+        redirectionTarget = _serverNoticesTarget;
       } else {
-       redirectionTarget = _userNoticesTarget;
+        redirectionTarget = _userNoticesTarget;
       }
     }
     break;
     if(redirectionTarget & BufferSettings::StatusBuffer) {
       const NetworkItem *netItem = findNetworkItem(msg.bufferInfo().networkId());
       if(netItem) {
-       updateBufferActivity(netItem->statusBufferItem(), msg);
+        updateBufferActivity(netItem->statusBufferItem(), msg);
       }
     }
   } else {
 
 
   if(Quassel::isOptionSet("debugmodel")) {
     connect(this, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
-           this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
+            this, SLOT(debug_rowsAboutToBeInserted(const QModelIndex &, int, int)));
     connect(this, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
-           this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
+            this, SLOT(debug_rowsAboutToBeRemoved(const QModelIndex &, int, int)));
     connect(this, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
-           this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
+            this, SLOT(debug_rowsInserted(const QModelIndex &, int, int)));
     connect(this, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
-           this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
+            this, SLOT(debug_rowsRemoved(const QModelIndex &, int, int)));
     connect(this, SIGNAL(dataChanged(const QModelIndex &, const QModelIndex &)),
-           this, SLOT(debug_dataChanged(const QModelIndex &, const QModelIndex &)));
+            this, SLOT(debug_dataChanged(const QModelIndex &, const QModelIndex &)));
   }
 }
 
 }
 
 QModelIndex TreeModel::index(int row, int column, const QModelIndex &parent) const {
-  if(!hasIndex(row, column, parent))
+  if(row < 0 || row >= rowCount(parent) || column < 0 || column >= columnCount(parent))
     return QModelIndex();
 
   AbstractTreeItem *parentItem;
 
 QModelIndex TreeModel::parent(const QModelIndex &index) const {
   if(!index.isValid()) {
-    qWarning() << "TreeModel::parent(): has been asked for the rootItems Parent!";
+    // ModelTest does this
+    // qWarning() << "TreeModel::parent(): has been asked for the rootItems Parent!";
     return QModelIndex();
   }
 
 
 void TreeModel::connectItem(AbstractTreeItem *item) {
   connect(item, SIGNAL(dataChanged(int)),
-         this, SLOT(itemDataChanged(int)));
+          this, SLOT(itemDataChanged(int)));
 
   connect(item, SIGNAL(beginAppendChilds(int, int)),
-         this, SLOT(beginAppendChilds(int, int)));
+          this, SLOT(beginAppendChilds(int, int)));
   connect(item, SIGNAL(endAppendChilds()),
-         this, SLOT(endAppendChilds()));
+          this, SLOT(endAppendChilds()));
 
   connect(item, SIGNAL(beginRemoveChilds(int, int)),
-         this, SLOT(beginRemoveChilds(int, int)));
+          this, SLOT(beginRemoveChilds(int, int)));
   connect(item, SIGNAL(endRemoveChilds()),
-         this, SLOT(endRemoveChilds()));
+          this, SLOT(endRemoveChilds()));
 }
 
 void TreeModel::beginAppendChilds(int firstRow, int lastRow) {