cleanErrors function added