Improved the simulation code for critical values [skip_ci]