Improved error handling in signal handlers