Fix crashes on empty lists