improve the code when an error appears