                 return
             }
 
+            let messagesCount = self.messagesQuery.count
+
             if insertions.count > 0 {
                 var newMessages: [Message] = []
                 for insertion in insertions {
+                    guard insertion < messagesCount else { continue }
                     let newMessage = Message(value: self.messagesQuery[insertion])
                     newMessages.append(newMessage)
                 }

                return
            }

            let messagesCount = self.messagesQuery.count

            if modifications.count > 0 {
                DispatchQueue.main.async {
                    let isAtBottom = self.chatLogIsAtBottom()

                            var indexPathModifications: [Int] = []

                            for modified in modifications {
                                guard modified < messagesCount else { continue }

                                let message = Message(value: self.messagesQuery[modified])
                                let identifier = message.identifier
