Fix bug in computation of error derivative when flags are not all set to 1.