Improved some error handling.