Improved crash handler function.