Improved error handling in background jobs