formatErrors function added