Fix: avoid crash and add logs