Beginning of error calculation