MonteCarlo implementation from @AdamSimpson