Fix error handler function and erase log