Only one question here: Why not remove the thread right after thread message retrieved, and we only delete the messages while all the messages retrieved, therefore we don't need threadsToRemove here. Maybe you have UI display concern about this implementation?