Improved error message logging