Improved last error

Improve performance saving last error value.