fix error logging loop bug