adding code for errors calculations