Improve error logging