Improved logging and error messages