imporved error logging