fixed error calculation