modified montecarlo function so that if the loop abort prematurely, outcome can still be calculated