Some fixes to improve determinism