Improved resource management and error handling.