fix panic handling