Improved the way errors are logged