Improved memory error handling.