vol 2: Adding some code from vol1 for error calculation.