Safe implementation of Monte Carlo tests.