Partial rewrite of mark bad trials.
Removed dead code.