Fix a bug on deterministic mode 2. Needs to be tested