Improves exception handling and logging output