91-117: Can we extract code like this into separate methods? (e.g. here maybe something like check_message_id or whatever makes sense)