Fix issues with error calculations