Make last error handling thread safe. ref #11