Fix casting when returning from panic