fixed a bug in witness generation.